What is the cause of MySQL query timeout? What should we do? The following describes how to solve the MySQL query timeout problem in detail.
- mysql>show variables like '%timeout';
-
The output is as follows:
- +----------------------------+-------+
- | Variable_name | Value |
- +----------------------------+-------+
- | connect_timeout | 5 |
- | delayed_insert_timeout | 300 |
- | interactive_timeout | 28800 |
- | net_read_timeout | 30 |
- | net_write_timeout | 60 |
- | slave_net_timeout | 3600 |
- | wait_timeout | 28800 |
- +----------------------------+-------+
-
Interactive_timeout takes effect after the CLIENT_INTERACTIVE option is set in mysql_connect () and is assigned as wait_timeout;
Mysql> set wait_timeout = 10; valid for the current interactive link;
Mysql> set interactive_timeout = 10; valid for subsequent interaction links;
The timeout time is measured in seconds and starts from the time after the last SQL statement is executed. If the current idle time exceeds this time, the variable is forcibly disconnected.
Interactive_timeout (commonly used)
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.
Translation: idle timeout time for client-server interaction. This system variable takes effect only when the "MYSQL_CLIENT_INTERACTIVE" flag is set when the client connects to the server. For example:
- // Enable MYSQL_CLIENT_INTERACTIVE mode to connect to the Database Server
-
- $ Link = mysql_connect ($ host, $ user, $ pwd, false, MYSQL_CLIENT_INTERACTIVE );
-
How to adjust the MySQL Query Buffer
How MySQL query optimizer works
In-depth parsing of MySQL query Cache Mechanism
Common MySQL command line tools
Implementation of MySQL non-repeated Query