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';


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.为了保证连接池的连接有效,所以修改连接池属性如下:

<!-- 配置dbcp数据源 -->  
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">  
        <property name="driverClassName" value="${dbcp.driver}" />  
        <property name="url" value="${dbcp.url}" />  
        <property name="username" value="${dbcp.username}" />  
        <property name="password" value="${dbcp.password}" />  
        <property name="maxActive" value="${dbcp.maxActive}"/>  
        <property name="minIdle" value="${dbcp.minIdle}"/>  
        <property name="maxWait" value="${dbcp.maxWait}"/>
        <property name="timeBetweenEvictionRunsMillis" value="64800" />
        <property name="testWhileIdle" value="true" />
        <property name="validationQuery" value="select 1 from dual" />
        <property name="testOnBorrow" value="true" />
</bean>

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


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值