Install Mysql in Ubuntu without Internet [Solved]


Today, i had to install mysql in an Ubuntu 12.04 64 bit precise instance. Ideally on an instance connected to the internet, issue the following command

sudo apt-get install mysql-server mysql-client

and you are ready to rock n roll !!

But that’s when your machine is directly connected to the internet. What do you do when you don’t have internet access on the machine?

Some scratching of the head and some more googling led me to this. You have to individualy download the required debian packages on a different machine, transfer them to your target machine and then install them using the dpkg command in the following order. Im sharing it here for self reference and for anyone else who would find this useful.

sudo dpkg -i libnet-daemon-perl_0.43-1_all.deb
sudo dpkg -i libplrpc-perl_0.2020-2_all.deb
sudo dpkg -i libdbi-perl_1.622-1_amd64.deb
sudo dpkg -i mysql-common_5.5.32-0ubuntu0.12.04.1_all.deb
sudo dpkg -i libmysqlclient18_5.5.32-0ubuntu0.12.04.1_amd64.deb
sudo dpkg -i libdbd-mysql-perl_4.021-1_amd64.deb
sudo dpkg -i mysql-client-core-5.5_5.5.32-0ubuntu0.12.04.1_amd64.deb
sudo dpkg -i libterm-readkey-perl_2.30-4build3_amd64.deb
sudo dpkg -i mysql-client-5.5_5.5.32-0ubuntu0.12.04.1_amd64.deb
sudo dpkg -i mysql-server-core-5.5_5.5.32-0ubuntu0.12.04.1_amd64.deb
sudo dpkg -i mysql-server-5.5_5.5.32-0ubuntu0.12.04.1_amd64.deb
sudo dpkg -i mysql-server_5.5.32-0ubuntu0.12.04.1_all.deb
sudo dpkg -i libhtml-template-perl_2.9-2_all.deb


Note : The packages mentioned above are meant specifically for the ubuntu 12.04 precise version. The required packages might vary from version to version. However the list above will give you a general sense of direction in case you land up in a situation like mine !!

Cheers !!
The Nonsense Blogger !!

Advertisements

Mysql – Configuring Access from a different Host


I just configured access to a mysql server from a machine outside the server machine. I find that there are a couple of steps that you need to remember. Just posting it here for my self reference and for any one else who would find it useful.

Enabling access to Mysql server from a different machine requires you to do the following two steps.

1. Mysql has to be configured so that it can bind on a host ip/address ( By default it listens only on localhost)

In my.cnf, under [mysqld] change bind-address to Host IP or Host Name. By default this attribute will be set to localhost. Find below, the relevant section of my.cnf file (Find higlighted the bind-address attribute)

[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
bind-address = 192.168.1.45
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
myisam-recover = BACKUP
query_cache_limit = 1M
query_cache_size = 16M

2. Now restart mysql service using any of the following commands

restart mysql
/etc/init.d/mysql restart

3. Give priviliges to the required users – For access from different hosts

Format : GRANT ALL on databasename.* to username@HostIP identified by ‘userpassword’;
Example : GRANT ALL on test.* to tj@192.168.1.50 identified by ‘tjpassword’;

This will give access to user tj from Host 192.168.1.50 to database test. If you want to see the current priviliges for user tj, use the following command.

Format : show grants for username@hostip
Example : show grants for tj@192.168.1.50;

This will show all the grants given to user tj connecting from 192.168.1.50

Note : In case you encounter the following exception (like i did). Now you know what you’ve got to do right !!

java.sql.SQLException: null, message from server: "Host 'XXXX' is not allowed to connect to this MySQL server"

Hope this helps.

Cheers,
The Nonsense Blogger !!

mysqldump utility – some useful no nonsense stuff


mysqldump is a great mysql utility that can be used for backing up and restoring existing mysql databases. Find below, some of the most useful stuff which can be accomplished using this utility.

I. Back Up and Restore a DB

Format : mysqldump -h domainname -u username -ppassword databasename > dumpfile.sql
Example : mysqldump -h localhost -u root -proot test > testdb_dump.sql

You can restore the database using the following commnad

Format : mysql -hdomainname -u username -ppassword databasename < dumpfile.sql
Example : mysql -hlocalhost -u root -proot test_new < testdb_dump.sql

This will dump the contents of testdb_dump.sql into the database test_new. Only thing that you need to make sure is that test_new already exists in your mysql.

II. Back Up only table structure

Format : mysqldump -d -h domainname -u username -ppassword databasename > dumpfile.sql
Example : mysqldump -d -h localhost -u root -proot test > testdb_dump.sql

The only difference here is the -d switch which isntructs mysql not to dump the data.

III. Back Up multiple databases

Format : mysqldump -h domainname -u username -ppassword --databases database1 database2 ... database n > dumpfile.sql
Example : mysqldump -h localhost -u root -proot --databases test test_new > testAndTest_NewDump.sql

IV. Back Up all databases

Format : mysql -h domainname -u username -ppassword --all-databases > dumpfile.sql
Example : mysql -h localhost -u root -proot --all-databases > allDatabasesDump.sql

V. Back Up a spcific table

Format : mysql -h domainname -u username -ppassword databasse table > dumpfile.sql
Example : mysql -h localhost -u root -proot test test_tabale > testtabledump.sql

For more on mysqldump, refer the official documentation @ : http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

Cheers,
The Nonsense Blogger !! 🙂

JSON Jackson Example


JSON has been a popular data exchange format for some time now. What impresses me the most is it’s light weightedness and simplicity.Java has it’s fair share of JSON libraries which can be used for processing and creating JSON. Amongst all, Jackson beats the competion in popularity in the developer community.

Jackson is a multi-purpose Java library for processing JSON data format. Jackson aims to be the best possible combination of fast, correct, lightweight, and ergonomic for developers – From the Jackson Wiki

Here, i will demonstrate how to create JSON string from Java Object and vice versa. Without any further nonsense, lets get started with the example.

First let’s create the custom Employee object which we will use to generate the JSON Output. The Employee object comprises of an id(integer), name(String), department – represented by another custom class ‘Department’ and list of teammates(arraylist of Strings).

Department department = new Department(1, "IT");
List teamMates = new ArrayList() {
private static final long serialVersionUID = 1L;
{
add("karian");
add("jmm");
add("cp");
}
};
Employee employee = new Employee(101, "TJ", department, teamMates);

Now we will use the Jackson Library class ‘ObjectMapper’ to generate the JSON equivalent for the Employee Object constructed above.

ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(employee);

That’s it and this returns the following JSON output.

{"employeeId":101,"teamMates":["karian","jmm","cp"],"employeeName":"TJ","department":{"departmentId":1,"departmentName":"IT"}}

Let’s use the same generated JSON output to create the Employee object

String json = "";// Assign the above string here
ObjectMapper mapper = new ObjectMapper();
Employee employee = mapper.readValue(json, Employee.class);


The readValue() method accepts two parameters, the json input as String and the Class whose instance it should generate from the json input.

Wasn’t that easier than you thought ?

You can download the full code from this git repo : https://github.com/jollyarun/jackson-demo.git

Cheers !!
The Nonsense Blogger !!

JavaHL Issues with Eclipse Plugin


Issue with JavaHL library when using Eclipse

While using the subversion plugin ‘sublipse’ in Eclipse IDE, i ran into the following problem

Failed to load JavaHL Library.
These are the errors that were encountered:
no libsvnjavahl-1 in java.library.path
no svnjavahl-1 in java.library.path
no svnjavahl in java.library.path
java.library.path = /usr/lib/jvm/java-6-sun-1.6.0.03/jre/lib/i386/client::/
usr/lib/jvm/java-6-sun-1.6.0.03/jre/lib/i386::/usr/lib/firefox:/usr/lib/
firefox/:/usr/java/packages/lib/i386:/lib:/usr/lib

This is because the JavaHL library used by the SVN plugin in Eclipse to interface with SVN Server is missing or not available. There are two ways to rectify this.

  1. Install the JavaHL library and point eclipse to this.
  2. Use ‘PureSVNKit’ in SVN Preferenves in Eclipse ( Window -> Preferences -> Team -> ‘SVN Preferences’ )

I went for the first one. Here is how you do it

1. Install libsvn. In ubuntu, use the following command

sudo  apt-get install libsvn-java

2. This will install the file libsvnjavahl-1.so into the /usr/lib/jni directory. Standard installations of eclipse will automaticall pick it up. ( Only a restart of eclipse is necessary )

3. For non standard installations of eclipse, you wil need to edit the ‘eclipse.ini’ file in the eclipse home directory. To the ‘vmargs’ section of the file, add the following detail

-Djava.library.path=/usr/lib/jni

Find below, the contents of my eclipse.ini

-startup
plugins/org.eclipse.equinox.launcher_1.0.200.v20090520.jar
–launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_1.0.200.v20090520
-product
org.eclipse.epp.package.java.product
-showsplash
org.eclipse.platform
–launcher.XXMaxPermSize
1024m
-vm
/home/mindtree/java/jdk1.6.0_22/jre/bin
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Djava.library.path=/usr/lib/jni
-XX:MaxPermSize=1024m
-Xms40m
-Xmx512m
-vm
/home/mindtree/java/jdk1.6.0_22/jre/bin

What you are doing here is , we are passing the library location to the VM whcih runs Eclipse. So eclipse will look for ‘library files’ in this location as well.

For more on JavaHL, use the JavaHL FAQ @ http://subclipse.tigris.org/wiki/JavaHL

Servicemix Tweaks to improve App Performance


The story behind this post

I have been using the Servicemix ESB ( Version 3.3.1 ) for quite some time for an Integration project. In quick words, this is how the App Architecture looks like.

The ActiveMq component embedded inside the SMX recieves JMS messages from an external client. Now, i have a Camel processor listening to the ActiveMQ broker ( ie the queues set up on the broker ). When a message arrives in of the queues, the camel PROCESSOR picks it up and forwards it to a BPEL process being executed by the ODE BPEL Engine ( Version 1.3.3 ). Within the BPEL process, it calls webservices hosted outside the ESB environment through an HTTP Provider Binding component.

The Problem

When the load to the App increases ( ie high number of concurrent requests ) , the BPEL engine fails to handle some of the requests passed to it and it inevitably throws the No Such Channel Exception eventually hangs.

The Solution

After a few days of frantic searching and posts on Apache Servicemix and ODE messageboards, this is what i found out.

The reason why the BPEL Engine stops responding to requests is because of the following reasons

1. Servicemix Thread Freeze :  ie there are too less number of threads within the servicemix to process these request.

Solution : This can be solved by re configuring the Threadconfiguration specified in the servicemix.properties in the conf folder in Servicemix. After reconfiguring , my configuration looks like this

servicemix.corePoolSize    = 100
servicemix.maximumPoolSize = 200
servicemix.queueSize       = 10

The corePoolSize specifies the number of initial threads available inside Servicemix. The quesize specifies the number of requests which will be queued before starting to spawn new threads up till a maximum limit as specified by the maximumPoolSize.

Find more about the Servicemix Thread Pool Executor (TPE ) here

2. Not enough threads within the BPEL Engine to handle the different process activities.

Solution : This can be solved by reconfiguring the corepoolsize property mentioned in the ode-jbi.properties file of the ode bpel engine. The ode engine comes inazipped format, so u will have to unzip the file, edit the ode-jbi.properties file and then re-zip and redeploy it again.

Find below, the configuration that i use

ode-jbi.threads.pool.size=20

The Story Now

The BPEL Engine has stopped hanging ie it doesn’t miss any requests anymore, but on the flip side the NoSuchChannelException continues to flood the Servicemix logs. Maybe, there is more to it than what meets the eye.

Hoping to solve that and get it posted here at the earliest.

Cheers,

The Nonsense Blogger !!

Zip command in Ubuntu


 

Zipping a File

Format : zip <filename.zip> dir1 dir2…..

Example : zip abc.zip test1/ test2/

This creates a zip file abc.zip with the contents of  folders test1 and test2

 

Unzipping a File

Format : unzip <filename.zip>

Example : unzip abc.zip

This unzips the contents of abc.zip to the current directory location

 

Unzipping a File to a specific folder

Format : unzip <filename.zip> -d dirname/

Example : unzip abc.zip -d unzip_dir/

This creates a folder unzip_dir and then unzips the contents of abc.zip to that folder.

 

Regards,

The NonsenseBlogger