当前位置:   article > 正文

com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully_the last packet successfully received from the ser

the last packet successfully received from the server was 34 milliseconds ag

服务器数据库间断性的会出现数据库连接异常的报错,报错异常为

### Error querying database. Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 34,101 milliseconds ago. The last packet sent s

uccessfully to the server was 34,103 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before us

e in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

--由于设置的超时时间比较短,只有30秒,mysql服务没有设置失败重连,因此服务就有偶尔出现这个异常

-- 查看timeout参数列表

show global variables like '%timeout%'

--第一种方式,当时生效,重启mysql服务后失效

--交互式连接超时时间设置和非交互式连接超时

-- 参考说明:https://www.cnblogs.com/ivictor/p/5979731.html

set global wait_timeout=28800;

set global interactive_timeout=28800;

--第二种方式,修改my.cnf文件,永久生效,但是需要重启mysql服务

sudo vi /etc/my.cnf

--增加如下配置

wait_timeout=28800

interactive_timeout=28800

-- 保存后重启mysql服务

sudo systemctl restart mysqld

--重启后查看参数是否生效

show global variables like '%timeout%'

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/1014720
推荐阅读
相关标签
  

闽ICP备14008679号