`
byx5185
  • 浏览: 112377 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

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

    博客分类:
  • J2EE
阅读更多
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 超时时间设置
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics