赞
踩
服务器数据库间断性的会出现数据库连接异常的报错,报错异常为
### 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%'
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。