Home >Database >Mysql Tutorial >Why Does My MySQL Connection Timeout After 60 Seconds, Even Though `wait_timeout` Is Set Higher?
MySQL server disconnected after 60 seconds
Problem background
I am executing A SQL query that was previously working fine encountered an error, which timed out after 60 seconds and threw an error. Although the query is slow, it's run as part of a nightly task, so that's not a problem per se (so please don't suggest me to optimize it).
Problem Details
I reproduced the error by running "select SLEEP(120); (see below) from PHP. However, running the same from the MySQL client The statement will succeed (return 0). I tried adjusting wait_timeout (set to 28800) but without success I also restarted the database server and the machine itself
the error always times out after 60 seconds. I think it's most likely a setup issue rather than a resource limit issue
System Information
Test code, output and SHOW VARIABLES
[The results of test code, output and SHOW VARIABLES are in Omitted here]
Solution
The php option mysql.connect_timeout is the source of this problem. It is not only used for connection timeout but also for waiting for the first request from the server. A response. You can increase it like this:
ini_set('mysql.connect_timeout', 300);
ini_set('default_socket_timeout', 300);
The above is the detailed content of Why Does My MySQL Connection Timeout After 60 Seconds, Even Though `wait_timeout` Is Set Higher?. For more information, please follow other related articles on the PHP Chinese website!