>  기사  >  데이터 베이스  >  mysql: Communications link failure解决_MySQL

mysql: Communications link failure解决_MySQL

WBOY
WBOY원래의
2016-06-01 13:34:321226검색

bitsCN.com

mysql: Communications link failure解决

 

使用Connector/J连接MySQL数据库,程序运行较长时间后就会报以下错误: 

 

Communications link failure,The last packet successfully received from the server was *** millisecond ago.The last packet successfully sent to the server was ***  millisecond ago。 

 

其中错误还会提示你修改wait_timeout或是使用Connector/J的autoReconnect属性避免该错误。 

 

MySQL服务器默认的“wait_timeout”是28800秒即8小时,意味着如果一个连接的空闲时间超过8个小时,MySQL将自动断开该连接,而连接池却认为该连接还是有效的(因为并未校验连接的有效性),当应用申请使用该连接时,就会导致上面的报错。 

 

解决办法有两个: 

一是修改my.cnf: 

 

[mysqld]  

wait_timeout=31536000  

interactive_timeout=31536000  

 

将过期时间修改为1年。 

 

二是在连接URL上添加参数:&autoReconnect=true&failOverReadOnly=false 

bitsCN.com
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.