Change wait_timeout and interactive_timeout in MySQL

wait_timeout – The number of seconds that the server waits for activity in a non-interactive connection before closing it.
At the time of connection, wait_timeout is taken from the global value wait_timeout or interactive_timeout depending on the client type (as defined by the CLIENT_INTERACTIVE connect option for mysql_real_connect ())

Connect to MySQL and see the current value:

mysql -u USER -p
show variables like "wait_timeout";
show variables like "interactive_timeout";
quit;

By default, the values wait_timeout and interactive_timeout are 28800 seconds = 8 hours.
You can set minimum 1, maximum – 31536000, maximum (for Windows) – 2147483.

You can change the value of wait_timeout by executing the SQL query, for example:

set global wait_timeout = 28800;
set global interactive_timeout = 28800;

That the set value has not been reset, it needs to be specified in the file /etc/mysql/my.cnf, in the mysqld block:

[mysqld]
wait_timeout = 28800
interactive_timeout = 28800

Change connect_timeout in MySQL

connect_timeout – the number of seconds that the mysql server waits for the connection package before terminating the connection.

Connect to MySQL and see the current value:

mysql -u USER -p
show variables like "connect_timeout";
quit;

The value of connect_timeout can be specified in the file /etc/mysql/my.cnf, for example:

[mysqld]
connect_timeout=10

In real time, you can change by executing the SQL query (after restarting MySQL it will be reset to the standard or specified in the configuration file):

SET GLOBAL connect_timeout=10;

The standard value is 10, the minimum value is 2, the maximum is 31536000.