Home >Database >Mysql Tutorial >Why Does My MySQL Connection Timeout After 60 Seconds, Even Though `wait_timeout` Is Set Higher?

Why Does My MySQL Connection Timeout After 60 Seconds, Even Though `wait_timeout` Is Set Higher?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-20 03:05:02328browse

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

  • Windows Server 2003
  • MySQL 5.1. 36-community
  • PHP 5.3

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn