mysql 报错Communications link failure,The last packet successfully received from the server was × mill

来源:互联网 发布:mac vim 退出编辑 编辑:程序博客网 时间:2024/06/05 13:35

1、报错信息

Communications link failureThe last packet successfully received from the server was 510,815 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.

2、报错原因

1、Mysql服务器默认的“wait_timeout”是8小时【也就是默认的值默认是28800秒】,也就是说一个connection空闲超过8个小时,Mysql将自动断开该connection,通俗的讲就是一个连接在8小时内没有活动,就会自动断开该连接。而应用连接池却认为该连接还是有效的(因为并未校验连接的有效性),当应用申请使用该连接时,就会导致上面的报错。2wait timeout的值可以设定,但最多只能是2147483,不能再大了。也就是约24.85天所以即使你MySQL通过my.ini 在# The TCP/IP Port the MySQL Server will listen onport=3306下面添加# this is myown dinifition for mysql connection timeoutwait_timeout=31536000interactive_timeout=31536000无论超过最大限度多大的数值,只能被MySQL解析为2147483

3、解决方案

(1)按照错误的提示,可以在JDBC URL中使用autoReconnect属性,实际测试时使用了autoReconnect=true&failOverReadOnly=false,不过并未起作用,使用的是5.1版本,可能真像网上所说的只对4之前的版本有效。

(2)增大mysql的wait_timeout属性值;(起不到实质性作用)

show variables like '%timeout';

这里写图片描述

(3)最好的解决方法:如果使用了c3p0连接池,可以配置idleConnectionTestPeriod 属性,每多少秒检查所有连接池中的空闲连接,把该值设置的小于mysql的wait_timeout值即可

阅读全文
1 0
原创粉丝点击