链接数据库报错(Communications link failure)之解决篇,

原创
2016-06-07 15:12:17 8139浏览

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:Communicationslinkfailure Thelastpacketsentsuccessfullytotheserverwas0millisecondsago.Thedriverhasnotreceivedanypacketsfromtheserver. 这个是最近我遇到的错误,就是一个普通的jdbc链接,

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

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

这个是最近我遇到的错误,就是一个普通的jdbc链接,(弄了我2天时间,主要系电脑的区别问题)

上网看了好多方法,主要由于数据库的内置问题引起:


mysql5将其连接的等待时间(wait_timeout)缺省为8小时。

解决方法:

1,先开mysql,输入 show global variables like 'wait_timeout'; 这句,就会显示出时间了,

mysql﹥ show global variables like 'wait_timeout';


+---------------+---------+


| Variable_name | Value |


+---------------+---------+


| wait_timeout | 28800 |


+---------------+---------+


1 row in set (0.00 sec)


解释:Mysql服务器默认的“wait_timeout”是8小时,也就是说一个connection空闲超过8个小时,Mysql将自动断开该connection。这就是问题的所。将会造成上面的异常。

2 set global wait_timeout=604800;

3 set global interactive_timeout=604800;

输入以上两句就可以解决这个问题了,


注意: 每个人的电脑不同,我在网上看了好多帖子,关于这个问题,略叼啊,什么都有得说的,为什么人家配置完还是不行,

重启mysql服务,先会生效,有的电脑就算重启mysql的服务都不会生效的,然后就只有重启了,我的就是这样,就算修改完mysql的配置都是不行的,最后重启电脑才连接上了数据库,我切底无语。 为何

详细介绍看:http://zeusami.iteye.com/blog/1112827





声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。