赞
踩
生产日志报错 显示日志异常为:
The last packet successfully received from the server was 5,007 milliseconds ago. The last packet sent successfully to the server was 5,005 milliseconds ago.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
问题原因:获取到的数据库连接超时了
解决方案:
1、在数据库连接上,加“&autoReconnect=true&failOverReadOnly=false”配置
2、设置数据库连接时间 wait_timeout
注意:连接池连接最大存活时长不应该超过数据库配置
数据库配置连接时间例如:
SET GLOBAL interactive_timeout = 300;
SET GLOBAL wait_timeout = 300;
3、若是是长事务导致的超时,则进行代码优化
相关URL参数可参考:
https://www.cnblogs.com/softidea/p/5765624.html
即使在创建Mysql时url中加入了autoReconnect=true参数,但是如果这个连接两次访问数据库的时间超出了服务器端wait_timeout的时间限制,还是会CommunicationsException: The last packet successfully received from the server was xxx milliseconds ago.
服务器端的参数可以用
show global variables like ‘wait_timeout’;
set global wait_timeout=10;
来进行设置,但是wait_timeout值不应该设的太高.
若是服务配置在nacos或者类似配置中心上面,若是配置信息没有采用热加载方式,需要重启服务器的哦。常规属性值自动刷新的方式:
1》@RefreshScope注解
2》@ConfigurationProperties
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。