Wednesday, September 26, 2012

Set JAVA_HOME / PATH

Login to your account and open .bash_profile file

$ vi ~/.bash_profile

et JAVA_HOME as follows using syntax export JAVA_HOME=<path-to-java>. If your path is set to /usr/java/jdk1.5.0_07/bin/java, set it as follows:

export JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java

Set PATH as follows:

export PATH=$PATH:/usr/java/jdk1.5.0_07/bin


$ source ~/.bash_profile

Monday, September 24, 2012

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)


A frequent error message received when using the mysql command line utility is: Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ While this error message can be frustrating, the solution is simple.


When connecting to a MySQL server located on the local system, the mysql client connects thorugh a local file called a socket instead of connecting to the localhost loopback address 127.0.0.1. For the mysql client, the default location of this socket file is /tmp/mysql.sock. However, for a variety of reasons, many MySQL installations place this socket file somewhere else like /var/lib/mysql/mysql.sock.
While it is possible to make this work by specifying the socket file directly in the mysql client command
mysql --socket=/var/lib/mysql/mysql.sock ...
it is painful to type this in every time. If you must do so this way (because you don’t have permissions to the file in the solution below), you could create an alias in your shell to make this work (like alias mysql=”mysql –socket=/var/lib/mysql/mysql.sock” depending on your shell).
To make your life easier, you can make a simple change to the MySQL configuration file /etc/my.cnf that will permanently set the socket file used by the mysql client. After making a backup copy of /etc/my.cnf, open it in your favorite editor. The file is divided into sections such as
[mysqld] datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock


[mysql.server] user=mysql
basedir=/usr/local/mysql

If there is not currently a section called [client], add one at the bottom of the file and copy the socket= line under the [mysqld] section such as:
[client] socket=/var/lib/mysql/mysql.sock
If there is already a [client] section in the my.cnf file, add or edit the socket line as appropriate. You won’t need to restart your server or any other processes. Subsequent uses of the mysql client will use the proper socket file.

Sunday, September 23, 2012

Install memcached on ubuntu

Brie Introduction :
"MemCached is a high-performance, distributed memory object caching system, generic in nature, but originally intended for use in speeding up dynamic web applications by alleviating database load."


Basically, it means it save and retrieve data in the server memory. This is typically used to remove the loads on the database server.
The logic of MemCached is very simple:
  • You verify if MemCached has the data you need, if so you simply use it.
  • if not, you save the data into MemCached and then use it.
run the following command to install memcached:

sudo aptitide install memcached

If you want to change the default settings, simply create the file and update the configuration.
First, create memcached configuration file:
vi  /etc/memcached.conf
Then, change the settings:
# Memory a usage in Mb
-m 16  
# default port  
-p 11211  
# user to run daemon nobody/apache/www-data or else 
-u nobody  
# only listen locally  
-l 127.0.0.1

Save and quit the file. Once this is complete, don't forget to restart the daemon:

sudo /etc/init.d/memcached restart
Now lets install for php

sudo aptitude install php5-memcache
Restart both services:

sudo /etc/init.d/memcached restart ; sudo /etc/init.d/apache2 restart
If you would like additional information about MemCached please visit: http://memcached.org/

Friday, September 21, 2012

Increase file handler on OS level


Open file : vi /etc/security/limits.conf

Add following two lines at bottom of limits.conf file


*       soft    nofile  65535
*       hard    nofile  65535

restart your machine. This will increase number of file handler to 65535. By-Default, Linux having 1024 handler.

Wednesday, September 19, 2012

Linux performance tuning


Kernels 2.6.16 and newer provide a mechanism to have the kernel drop the page cache and/or inode and dentry caches on command, which can help free up a lot of memory. Now you can throw away that script that allocated a ton of memory just to get rid of the cache...
To use /proc/sys/vm/drop_caches, just echo a number to it.


  1. To free pagecache: [root@host]# echo 1 > /proc/sys/vm/drop_caches
  2. To free dentries and inodes: [root@host]# echo 2 > /proc/sys/vm/drop_caches
  3. To free pagecache, dentries and inodes: [root@host]# echo 3 > /proc/sys/vm/drop_caches




This is a non-destructive operation and will only free things that are completely unused. Dirty objects will continue to be in use until written out to disk and are not freeable. If you run "sync" first to flush them out to disk, these drop operations will tend to free more memory.

Monday, September 17, 2012

ERROR 1126 (HY000) at line 38: Can't open shared library 'libmemcached_functions_mysql.so'

Hi,
    I am trying to install mysql-memcached connectivity. Once am trying this

mysql -uroot Producer <sql/install_functions.sql


it is giving me this error


ERROR 1126 (HY000) at line 38: Can't open shared library 'libmemcached_functions_mysql.so' (errno: 22 libmemcached.so.3: cannot open shared object file: No such file or directory)


Can one have idea, how can I resolved it..................

MySQL Optimize Table


The MySQL Optimize Table command will effectively de-fragment a mysql table and is very useful for tables which are frequently updated and/or deleted.

This statement requires SELECT and INSERT privileges for the table.
OPTIMIZE TABLE works only for MyISAMInnoDB, and (as of MySQL 5.0.16) ARCHIVE tables. It does not work for tables created using any other storage engine.
For MyISAM tables, OPTIMIZE TABLE works as follows:
  1. If the table has deleted or split rows, repair the table.
  2. If the index pages are not sorted, sort them.
  3. If the table's statistics are not up to date (and the repair could not be accomplished by sorting the index), update them.


Example:
We have a table called articles which has many thousands of rows which are often inserted, updated and deleted. We can see from the table description below that the table contains variable length column data types:

mysql> desc articles;
+----------------+--------------+------+-----+---------+----------------+
| Field  | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+----------------+
| id  | int(11) | NO   | PRI | NULL    | auto_increment |
| content        | text         | NO   |     | NULL    |                |
| author_id      | int(11)      | YES  |     | NULL    |                |
| article_title  | varchar(120) | YES  |     | NULL    |                |
| article_hash   | int(11)      | YES  |     | NULL    |                |
+----------------+--------------+------+-----+---------+----------------+

6 rows in set (0.00 sec)

If we look at the size of the table on disk we can see that it around 190MB. If we query the table on a column which is indexes we can see the average query response time: 
e.g.
mysql> select count(*) from articles where article_title like 'The%';
+----------+
| count(*) |
+----------+
|    15830 |
+----------+
1 row in set (0.63 sec)

If we now optimize the table with the following command:
mysql> optimize table articles;
+-----------------------+----------+----------+----------+
| Table                 | Op       | Msg_type | Msg_text |
+-----------------------+----------+----------+----------+
| books.articles        | optimize | status   | OK       |
+-----------------------+----------+----------+----------+
1 row in set (6.27 sec)
This has the effect of defragmenting the table and reducing the size of the table on disk down to 105MB. It also has a very positive affect on query performance, reducing the select query response time from 0.63 to 0.39 seconds. N.B. the mysql query cache was turned off to demonstrate.
mysql> select count(*) from articles where article_title like 'The%';
+----------+
| count(*) |
+----------+
|    15830 |
+----------+
1 row in set (0.39 sec)