com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link fai

mysql数据库异常:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 59,029 milliseconds ago. The last packet sent successfully to the server was 1 milliseconds ago.

数据源配置:

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/new_schema?characterEncoding=utf-8" />
<property name="user" value="root" />
<property name="password" value="root" />
<property name="minPoolSize" value="2" />
<property name="maxPoolSize" value="5" />
<property name="idleConnectionTestPeriod" value="60" />
<property name="acquireIncrement" value="3" />
<property name="maxStatements" value="0" />
<property name="maxStatementsPerConnection" value="5" />
<property name="preferredTestQuery" value="SELECT 1" />
<property name="debugUnreturnedConnectionStackTraces" value="true" />
<property name="numHelperThreads" value="5" />
<property name="maxIdleTime" value="200"/>
<property name="maxIdleTimeExcessConnections" value="60" />
</bean>



错误原因:
使用了HAProxy + cobar + mysql的架构,HAProxy中的timeout设置为50秒导致了上面的错误。


----------------------分割线----------------------------
还有网友分享了其他原因:
maxIdleTimeExcessConnections的时间小于maxIdleTime导致的。

不建议使用maxIdleTimeExcessConnections。
如果要使用,应该和maxIdleTime一样。


查询会话变量:
mysql> show session variables like '%wait%';
+--------------------------+----------+
| Variable_name | Value |
+--------------------------+----------+
| innodb_lock_wait_timeout | 50 |
| innodb_spin_wait_delay | 6 |
| lock_wait_timeout | 31536000 |
| wait_timeout | 28800 |
+--------------------------+----------+
4 rows in set (0.00 sec)

查询全局变量:

mysql> show global variables like '%wait%';
+--------------------------+----------+
| Variable_name | Value |
+--------------------------+----------+
| innodb_lock_wait_timeout | 50 |
| innodb_spin_wait_delay | 6 |
| lock_wait_timeout | 31536000 |
| wait_timeout | 30 |
+--------------------------+----------+
4 rows in set (0.00 sec)


http://forums.pentaho.com/showthread.php?140518-MySql-Communications-link-failure-SOLVED
http://wiki.pentaho.com/display/EAI/MySQL
The MySQL server parameter "net_write_timeout" defaults to 60 seconds.
I found that by increasing this to a larger value, the exception goes away.
Then we do not have to turn off the result set cursor and we don't need
to read the entire result set into memory by turning off result set streaming (cursor emulation)
This parameter is set in my.ini. I set it to 1800, but probably a
smaller value would suffice.


http://cloudbbs.org/forum.php?mod=viewthread&tid=11629
MySQL连接30秒不使用会自动丢失,你可以参考以下配置
<property name="maxPoolSize" value="12" />
<property name="minPoolSize" value="0" />
<property name="maxStatements" value="100" />
<property name="initialPoolSize" value="3" />
<property name="maxIdleTime" value="10"/>
<property name="idleConnectionTestPeriod" value="10" />
<property name="testConnectionOnCheckin" value="true" />
<property name="testConnectionOnCheckout" value="false" />
<property name="preferredTestQuery" value="SELECT 1 FROM DUAL" />


http://serverfault.com/questions/439329/haproxy-client-timeouts-when-connecting-from-jdbc-pool
Haproxy 超时时间设置
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值