Changing MySQL wait_timeout variable

Dilsi Chandrasena
2 min readApr 9, 2018
  • We can set the wait_timeout variable, for a session or globally.
  • If we set the wait_timeout variable for a session, it will valid only for a particular session. But when we set the wait_timeout variable globally it will valid for all the sessions.

To run these commands, first we need to login to MySql server.

We can check the current values of the wait_timeout variable using below commands.

SHOW SESSION VARIABLES LIKE “%wait_timeout%”; or SHOW SESSION VARIABLES LIKE “wait_timeout”;

  • Default wait_timeout value is 28800 seconds.

If we need to set this timeout for a session we can use below command.

SET session wait_timeout=300;

If we need to change the wait_timeout global value we should follow below steps.

1. Open the my.cnf file which resides in /etc/mysql directory.
2. Add below value with the mysqld blog to my.cnf file.

[mysqld]
wait_timeout=300
interactive_timeout = 300

3. Restart the MySQL server using command below

service mysql restart

4. Then we can see the wait_timeout variable has changed globally.

Before changing the global value,

After changing the global value,

--

--