Sleeping MySQL connections

asked Dec 28, 2012 in Database by Susan3 (880 points)
I usually encounter sleeping connections in MySQL, these are mainly connections that are no longer being used but haven’t been closed.
How do I prevent this, or decrease the amount of times these connections stay open for?
Any help would be appreciated.

1 Answer

0 like 0 dislike
answered Dec 28, 2012 by SmartHost (9,060 points)
You can enable  MySQL to decrease the how long a sleeping connection can remain open
1.Log into your server and make sure your MySQL instance is running.
2.Locate MySQL configuration file. On a Linux OS you would normally find it at "/etc/my.cnf".
3.Open your MySQL configuration file with any text editor, and add the following lines under "[mysqld]"
# Reduced wait_timeout to stop idle connections.
4.You can change the amount of time measured in seconds.
5.When you are done, save the file and then restart MySQL.