mysql-错误:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

来源:互联网 发布:迪杰斯特拉算法应用 编辑:程序博客网 时间:2024/06/02 20:38

系统登陆功能隔段时间就会发神经,点击登录没反应,状态码返回:500。开始以为是代码问题,后来查看日志发现以

下错误:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 0 ms ago 

通过mysql客户端命令查看:show global variables like 'wait_timeout';

显示为28000=8*3600,也就是说mysql默认的连接维持时间是8个小时,前一天晚上回去,到第二天过来,已经超过了8个小时,程序已经与mysql失去了连接,所以报错。

解决办法:

因为wait_timeout的最大值分别是24天/365天(windows/linux),所以我们可以修改超时的最大值。

programData文件夹下找到mysql目录中的my.ini文件,添加如下:

wait_timeout=2073600interactive_timeout=2073600


1 1