com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 11,226 milliseconds ago.
Caused by: java.net.SocketException: Connection reset by peer: socket write error
两种解决异常:“The last packet successfully received from the server was 11,226 milliseconds ago. ”的办法
出现异常”The last packet successfully received from the server was 11,226 milliseconds ago. “的大部分原因是由于数据库回收了连接,而系统的缓冲池不知道,继续使用被回收的连接所致的。
以mysql为例:
第一种解决办法,就是将mysql回收空闲连接的时间变长,mysql默认回收时间是8小时,可以在mysql目录下的my.ini(my.defaultini)中增加下面配置,将时间改为1天。
单位是秒,最大好像是24天:
[mysqld]
wait_timeout=86400
interactive_timeout=86400
本文详细介绍了当遇到MySQL异常“Thelastpacketsuccessfullyreceivedfromtheserverwas11,226millisecondsago.”时的两种解决方案。一种是通过修改MySQL配置文件my.ini中的wait_timeout和interactive_timeout参数来延长连接回收时间;另一种是配置连接池,使其能够检测并避免使用已被回收的连接。
2272

被折叠的 条评论
为什么被折叠?



