MySQL Configuration – Setting Client Timeout

MySQLtimeout

Is there a way to configure the timeout for inactive clients with mysql?

Example:
A MySQL DB has a limit of 100 client connections but some clients are not using the connection any more. I assume MySQL will eventually drop the connection but is this configurable?

Best Answer

There are a number of ...timeout... parameters that can be configured for a MySQL instance. Here are a few selected parameters (Ver. 8.x) for your convenience:

Reference: 5.1.7 Server System Variables (MySQL | Documentation)

interactive_timeout

The number of seconds the server waits for activity on an interactive connection before closing it. An interactive client is defined as a client that uses the CLIENT_INTERACTIVE option to mysql_real_connect(). See also wait_timeout.

wait_timeout

The number of seconds the server waits for activity on a noninteractive connection before closing it.

On thread startup, the session wait_timeout value is initialized from the global wait_timeout value or from the global interactive_timeout value, depending on the type of client (as defined by the CLIENT_INTERACTIVE connect option to mysql_real_connect()). See also interactive_timeout.

Answering Your Question

Is there a way to configure the timeout for inactive clients with mysql?

It depends. Globally you can define a timeout with the wait_timeout parameter of your MySQL instance. If you are using the specific option CLIENT_INTERACTIVE of the mysql_real_connect() function, then you can use the interactive_timeout parameter.