How To Add A Timeout Variable

Often with MySQL you may encounter sleeping connections, where are basically connections that are no longer in use but have not been closed. These sleeping connections are usually the result of code that is allowing persistant connections or code that has not set a variable to how long a connection to MySQL can stay open. However it is possible to lessen the impact by enabling MySQL to decrease how long a sleeping connection can stay open.

  1. Log into your server so that your MySQL instance runs on.
  2. Locate the MySQL configuration file. Normally on a Linux OS this is located at "/etc/my.cnf".
  3. Open the MySQL configuration file with a text editor. By default you have access to Pico, Nano or Vim / Vi.
  4. In the file, add the following lines under "[mysqld]"

  5. # Reduced wait_timeout to prevent idle clients holding connections.
    wait_timeout=15
    interactive_timeout=100

  6. You can also change the amount of time, which are measured in seconds.
    Once you have made the change, save the file and restart MySQL. The settings will not take affect until you do.