小工具知识网

当前位置: 首页 > 行业知识 > 解决MySQL报错:“The last packet sent successfully to the server was 0 milliseconds ago.”

行业知识

解决MySQL报错:“The last packet sent successfully to the server was 0 milliseconds ago.”

2026-11-08 10:40:09 来源:互联网转载

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

()

问题原因:

之所以出现异常,是由于数据库回收了连接,而系统的缓冲池不知道,继续使用被回收的连接所致的。

解决方案1:

方法就是将mysql回收空闲连接的时间变长,mysql默认回收时间是8小时,可以在mysql目录下的my.cnf中增加下面配置,将时间改为1天。

()

单位是秒,最大好像是24天:

 [mysqld]

wait_timeout=86400  //加上这一句

执行下面SQL语句查看超时时间

show global variables like 'wait_timeout'

解决方案2:

判断连接url是否正确(useSSL为false)

spring:  datasource:    url: jdbc:mysql://127.0.0.1:3306/demo?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false

上一篇:MySQL数据库游标(Cursor)的定义及使用和MySQL流程控制语句详解

下一篇:windows服务器性能测试怎么设置?