Solutions for Communications link failure



 

Using Connector/J to connect to the MySQL database, the following error will be reported after the program runs for a long time:

Communications link failure,The last packet successfully received from the server was *** millisecond ago.The last packet successfully sent to the server was ***  millisecond ago。

The error will also prompt you to modify wait_timeout or use the autoReconnect property of Connector/J to avoid the error.

Later, after checking some information, I found that there are quite a few people who have encountered this problem. Most of them only use the connection pool method to have this problem. It should be difficult for short connections to have this problem. Reason for this problem:

The default "wait_timeout " of the MySQL server is 28800 seconds or 8 hours, which means that if a connection is idle for more than 8 hours, MySQL will automatically disconnect the connection, but the connection pool thinks the connection is still valid (because the Check the validity of the connection), when the application applies to use the connection, it will cause the above error.

Modify the parameters of MySQL, the maximum wait_timeout is 31536000 , which is 1 year, and add in my.cnf:

[mysqld]

wait_timeout=31536000

interactive_timeout=31536000

Restart to take effect, you need to modify these two parameters at the same time.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326808386&siteId=291194637