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

1.尝试登录网站时失败,查看发现出现以下错误:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 259,809,499
 milliseconds ago.is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing
 connection validity before use in your application,increasing the server configured values for client timeouts, 
or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.


2.根据报错信息可以判断连接池中的连接Connection失效,即超过了有效时间wait_timeout。登录mysql后查看wait_timeout有效时间为28800,即八小时。
show global variables like 'wait_timeout';

Mysql报com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure错误_第1张图片


3.修改wait_timeout属性,调大数值为31536000(365天,linux最大值为一年)。在my.cnf配置文件中,[mysqlId]下添加wati_timeout、interactive_timeout属性,重启mysql。此时测试发现已经可以连接,基本解决了问题。

(1).编辑my.cnf配置文件

vi /etc/my.cnf
(2).添加wait_timeout属性

[mysqlId]
...
wait_timeout = 31536000
interactive_timeout = 31536000

(3).重启mysql

service mysqld restart


4.为了保证连接池的连接有效,所以修改连接池属性如下:

  
  
          
          
          
          
          
          
        
        
        
        
        

参考自:http://zeusami.iteye.com/blog/1112827


你可能感兴趣的:(mysql)