链接数据库报错(Communications link failure)

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。这就是问题的所。将会造成上面的异常。
set global wait_timeout=604800; 
3 set global interactive_timeout=604800;
输入以上两句就可以解决这个问题了,

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

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

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

猜你喜欢

转载自blog.csdn.net/u011418530/article/details/80446323