`
jzh84115
  • 浏览: 28377 次
  • 性别: Icon_minigender_1
  • 来自: 福州
文章分类
社区版块
存档分类
最新评论

mysql "Communications link failure due to underlying exception"错误

阅读更多
Communications link failure due to underlying exception

原因:Mysql服务器默认的“wait_timeout”是8小时,如果connection空闲超过8个小时,Mysql将自动断开该 connection。
在C3P0 pools中的connections如果空闲超过8小时,Mysql将其断开,而C3P0中的该connection仍然存在,如果这时有 Client请求connection,
C3P0将该断开的Connection提供给Client,将会造成上面的异常。
  
可以这么解决该问题:
使得Connection pools中connection的lifetime与Mysql的wait_timeout时间达到一致,或者测试Connection pools中connection的有效性。
在wait_timeout的时间为8小时的情况下:
C3P0增加以下配置信息:

//set to 'SELECT 1'     
preferredTestQuery = 'SELECT 1'  
//set to something much less than wait_timeout, prevents connections from going stale  
idleConnectionTestPeriod = 18000    
//set to something slightly less than wait_timeout, preventing 'stale' connections from being //handed out  
maxIdleTime = 25000  
//if you can take the performance 'hit', set to "true"  
testConnectionOnCheckout = true   

MySQL连接如果8小时未使用,在查询使用到该连接会报:

异常名称:com.mysql.jdbc.CommunicationsException
异常信息: Communications link failure due to underlying exception

如果是MySQL5以前的版本,需要修改连接池配置中的URL,添加autoReconnect=true

如果是MySQL5 以后的版本,需要修改my.cnf(或者my.ini)文件,在[mysqld]后面添加

wait_timeout = 172800
interactive-timeout = 172800

单位都是秒,记得必须都添加,否则不起作用,通过show variables查看wait_timeout的值。
分享到:
评论

相关推荐

    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...

    浅析mysql交互式连接&非交互式连接

    这可能导致应用程序在尝试使用这些已断开的连接时遇到“Communications link failure due to underlying exception”异常。 解决这个问题的方法通常包括以下几点: 1. 调整`wait_timeout`值,增加到更长的时间,以...

    JDBC 程序的常见错误及调试方法

    错误信息可能表现为“***municationsException: Communications link failure due to underlying exception”以及一个***.ConnectException异常。这通常意味着无法建立到数据库服务器的网络连接。解决方法是确认IP...

    解决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 ... The last packet sent successfully to the server was 47,795,922

    Introduction to Computing Systems From bits & gates to C & beyond

    Patt'Introduction to Computing Systems: From bits & gates to C & beyond', now in its second edition, is designed to give students a better understanding of computing early in their college careers in...

    mysql密码过期导致连接不上mysql

    mysql密码过期了,今天遇到了连接mysql,总是连接不上去, 错误现象1: An attempt by a client to checkout a Connection has timed out 第一次出现连接超时错误,第一反应是去修改cpool.checkoutTimeout参数为...

    MySQL分表和分区的具体实现方法

    MySQL数据库在处理大规模数据时,可能会遇到性能瓶颈,这时就需要采用分表和分区技术来优化。这两种技术的主要目的是提高查询效率、减少锁竞争,并降低单个表的数据量,从而提升系统的整体性能。 **垂直分表**是将...

    A Practical Guide to Designing with Data.pdf

    new ʻvisualizationsʼ are an attempt to explain the underlying information with a powerful visual impact. They take complex ideas and distil them into beautiful graphics revealing the ...

    LTE-Advanced: A Practical Systems Approach to Understanding 3GPP LTE

    It includes methodologies and results related to link-level and system-level evaluations of LTE-Advanced. It provides understanding and insight into the advanced underlying technologies in LTE-...

    An Introduction to Fluid Dynamics (Batchelor)

    His careful presentation of the underlying theories of fluids is still timely and applicable, even in these days of almost limitless computer power. This reissue ensures that a new generation of ...

    计算机网络第六版答案

    but the time when loss first occurs will be different from one experiment to the next due to the randomness in the emission process. 22. Five generic tasks are error control, flow control, ...

    Introduction to Matplotlib.rar

    Visualizing data in plots and figures exposes the underlying patterns in the data and provides insights. Good visualizations also help you communicate your data to others, and are useful to data ...

    Sparse channel estimation in millimeter wave communications

    an underlying two-dimensional cluster feature, we propose a two-dimensional sparse Bayesian learning method without a priori knowledge of two-dimensional angular spread patterns. It essentially ...

    Robust Visual Inertial Odometry Using a Direct EKF-Based Approach.pdf

    After detection, the tracking of the multilevel patch features is closely coupled to the underlying extended Kalman filter (EKF) by directly using the intensity errors as innovation term during the ...

Global site tag (gtag.js) - Google Analytics