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

2023-03-10,,

出现这种错误的大致情况如下:

1、数据库连接长时间未使用,断开连接后,再去连接出现这种情况。这种情况常见于用连接池连接数据库出现的问题

2、数据库连接的后缀参数问题

针对上述两种情况,解决方案如下

1、修改MySQL的参数,my.cnf位于/etc目录下,修改完成后,重启mysql

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

[mysqld]

wait_timeout=31536000

interactive_timeout=31536000

2、连接数据库的时候参数问题

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

3、直接修改mysql的参数,不用重启

进入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;

Communications link failure:The last packet successfully received from the server was 0 millisecond ago的相关教程结束。

《Communications link failure:The last packet successfully received from the server was 0 millisecond ago.doc》

下载本文的Word格式文档,以方便收藏与打印。