多语言展示
当前在线:181今日阅读:126今日分享:42

mysql长时间空闲报错

问题:通过spring 连接 mysql 会出现报错com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received from the server was 1,924,852 milliseconds ago. The last packet sent successfully to the server was 4 milliseconds ago.以及java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
方法/步骤
1

mysql版本为4的,可以直接修改配置文件即可解决。加入属性设置autoReconnect=true,但是这个对5以上的版本不起作用。

2

mysql版本5以上的,可修改wait_timeout参数,mysql默认的wait_timeout值为8小时,即28800秒。根据各自的业务可以设置不同的值。最大可设置31536000(即为1年)。不用重启mysql服务的修改方式,进入到mysql操作界面:

3

查看wait_timeout的值,命令:show global variables like 'wait_timeout';注意这里带上global这个是全局的。

4

修改wait_timeout值,命令: set global wait_timeout=86400;

5

检查是否修改成功,继续输入命令show global variables like 'wait_timeout';到这里就修改成功了。

6

方法二,就是修改mysql配置文件里面的参数。wait_timeout= 86400interactive_timeout =86400重启mysql服务后生效。

注意事项

mysql

推荐信息