Communications link failure:The last packet successfully received from the server was 0 millisecond

The general situation of this error is as follows:

1. The database connection has not been used for a long time, and this situation occurs after disconnecting and reconnecting. This situation is common in the problem of using the connection pool to connect to the database
2. The problem of the suffix parameter of the database connection

For the above two cases, the solution is as follows

1. Modify the parameters of MySQL, my.cnf is located in the /etc directory, after the modification is completed, restart mysql

wait_timeout最大为31536000即1年,在my.cnf中加入:

[mysqld]

wait_timeout=31536000

interactive_timeout=31536000

2. Parameter problem when connecting to the database

如果使用mysql版本为5.7+,驱动Driver使用的是:com.msyql.cj.jdbc.Driver
那么你必须在连接url后面添加
useSSL=false

3. Modify the parameters of mysql directly without restarting

进入mysql的命令行或者客户端
show global variables like '%wait_timeout%'; 

将wait_timeout 和interactive_timeout 设置的大一点。默认是8小时(28800)。
set global wait_timeout=604800;
set global interactive_timeout=604800;

刷新缓存
flush privileges;

If hard work is useful, what do you need genius for?

Guess you like

Origin blog.csdn.net/LookingTomorrow/article/details/121704921