Get rid of mysql sleep process

Some times there are many many sleep processes in your SQL connection. These sleep connections consume a lot of resources (RAM, cache and processor). This can cause your MySQL server slow down. If your MySQL server is not responding then the query to the database will take a lot of time. In such situations, your website will open very slowly.

This is really frustrating for webmasters. Here, I will show you how you can get rid of these sleep processes.What is sleep process and Why are there too many sleep process in MySQL?Sleep process are the connections waiting for new MySQL query. This can happen if the database connection is not closed properly. Or you are using mysql_pconnect() command in your php script.

How To Get Rite of Sleep Process?

It is very important to close the DB connection after the query is done.To do this, add mysql_close() function at end of the every script that has an open MySQL connection. It will close the connection and it will not go into sleep.There is another way to do so . If you have the root access to your server then you can edit my.cnf using following command

  $Locate my.cnf

It will show the location of MySQL configuration file then use following command to edit my.cnf

  $vi /etc/my.cnf

And add this line in my.cnf

  wait_timeout = 60

where time is in second Thus, the connections will automatically be closed after waiting for 60 seconds. These are little webmaster tips that can help you improve the performance of your website.


Liked It? Get Free updates in your Email

Delivered by feedburner

Leave a Reply

Your email address will not be published. Required fields are marked *