`
byx5185
  • 浏览: 113220 次
  • 性别: 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 超时时间设置
分享到:
评论

相关推荐

    解决Cause com.mysql.jdbc.exceptions.jdbc4.CommunicationsException

    Cause com.mysql.jdbc.exceptions.jdbc4.CommunicationsException The last packet successfully received from the server was 47,795,922 milliseconds ago. The last packet sent successfully to the server was...

    mysql 异常com.mysql.jdbc.CommunicationsException

    本次异常的具体描述为:“Communications link failure due to underlying exception: **BEGINNESTED EXCEPTION** java.io.EOFException STACK TRACE: java.io.EOFException at com.mysql.jdbc.MysqlIO.readFully...

    com.mysql.jdbc.PacketTooBigException: Packet for query is too large (11087 > 102

    `com.mysql.jdbc.PacketTooBigException` 是MySQL JDBC驱动抛出的一个异常,它表示在网络传输过程中,发送到服务器的数据包超过了MySQL服务器允许的最大大小。在描述中提到的错误信息 "Packet for query is too ...

    mysql数据库在springboot项目中启动报错问题.docx

    在给定的信息中,我们注意到一个具体的错误信息:“com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error:GlobalConfigUtils setMetaData Fail !”。这个错误提示表明在使用 MyBatis Plus 时出现...

    c-jdbc 详细配置方案

    C-JDBC,全称Cluster JDBC,是一款用于数据库集群的中间件,它允许应用程序同时访问和操作多个数据库,实现数据的同步交换。以下是对C-JDBC的详细配置方案及其相关知识点的解析: 1. **下载与安装**: - 从官方...

    bitronix 连接 MySQL 出现MySQLSyntaxErrorException 的解决方法

    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'hibernate' at sun.reflect.NativeConstructorAccessorImpl.new

    MySQL数据库连接异常汇总(值得收藏)

    在Centos上部署项目发现一个奇怪的问题,数据库连接一直抛异常。于是花了两个小时搜了各种数据库连接异常导致的原因,最终问题得以解决。同时,把解决过程中搜集到的异常信息汇总一下,当大家遇到...com.mysql.jdbc.exc

    linux 后台日志 mysql 错误异常的解释(推荐)

    1、Caused by: com.MySQL.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 56,201,339 milliseconds ago. The last packet sent successfully to the...

    mysqljdbc src

    MySQL JDBC,也称为MySQL Connector/J,是MySQL数据库与Java应用程序之间的桥梁,允许Java开发者通过JDBC(Java Database Connectivity)API连接并操作MySQL数据库。在"mysqljdbc src"中,我们探讨的是MySQL JDBC 5...

    Dbvisualizer安装及连接mysql oracle sqlServer配置

    对于MySQL,驱动类名通常是`com.mysql.jdbc.Driver`;Oracle则是`oracle.jdbc.driver.OracleDriver`;而对于SQL Server,驱动类名是`com.microsoft.sqlserver.jdbc.SQLServerDriver`。确保正确选择并输入这些信息,...

    mysql8驱动源码.zip

    7. **错误处理**:`com.mysql.cj.jdbc.exceptions` 包下的异常类封装了与数据库交互时可能出现的各种错误,便于开发者进行异常处理。 8. **连接池支持**:驱动支持常见的连接池框架,如 C3P0、HikariCP、Druid 等,...

    mysql-connector-java-5.1.12.rar 源代码

    MySQL Connector/J 5.1.12 是 MySQL 官方提供的用于 Java 应用程序...3. com.mysql.jdbc.exceptions 包:包含所有由 MySQL Connector/J 抛出的异常类,如 `com.mysql.jdbc.exceptions.MySQLSyntaxErrorException` 和 `...

    MyEclipse8.x 汉化

    4. **刷新界面**:重启MyEclipse后,大部分界面应该已经变为中文。如果某些地方仍显示英文,可能是因为汉化不完全或者有遗漏。此时,可以尝试清理MyEclipse的缓存,具体操作是关闭MyEclipse,删除.metadata\.plugins...

    java mysql驱动源码

    例如,`com.mysql.jdbc.exceptions`包下包含了一系列异常类,用于处理在数据库操作中可能出现的问题。`com.mysql.jdbc.JDBC4Connection`是JDBC 4版本的连接实现,增加了新的特性支持。 深入理解Java MySQL驱动源码...

    mysql的jar

    5. **异常处理**:当数据库操作遇到问题时,会抛出特定的异常,如`com.mysql.jdbc.exceptions.MySQLSyntaxErrorException`和`com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException`等。...

    mysql_jdbc连接数据库-错误提示.pdf

    Exception in thread "main" com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown database 'hrtrain' ``` **解决方法**: - 确认数据库名称是否正确。 - 检查MySQL服务状态,确保其正在运行。 #### 五...

    No operations allowed after statement closed.

    解决:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after statement closed.

    mysql-connector-java-5.1.33-bin.src源码

    6. **异常处理**: 源码中包含了大量的异常类,如`com.mysql.jdbc.exceptions.MySQLSyntaxErrorException`,这些异常类对应于MySQL数据库的各种错误情况,帮助开发者诊断和解决问题。 7. **性能优化**: MySQL ...

    mysql-connector-java-6.0.6源码

    6. **异常处理**:`com.mysql.jdbc.exceptions`包包含了所有可能抛出的MySQL特定异常,如`MySQLSyntaxErrorException`、`MySQLIntegrityConstraintViolationException`等,这些异常在遇到错误时被抛出,帮助开发者...

Global site tag (gtag.js) - Google Analytics