控制台报“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.at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)at java.lang.reflect.Constructor.newInstance(Constructor.java:526)at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1137)

二、解决办法

笔者出现这个问题是因为MySQL数据服务没有开启导致连接失败
笔者网上查找了一下资料,可能由于别的也会出现这种错误的原因,并做了如下总结:
第一种:MySQL数据服务没有开启导致连接失败
第二种:MySQL数据库设置成了外网不能访问,需要开启外网IP访问的功能。
第三种:可能是网络问题,导致连接不上,ping一下MySQL所在主机的IP
第四种:数据设置wait_timeout时间,在默认配置不改变的情况下,如果连续8小时内都没有访问数据库的操作,再次访问mysql数据库的时候,mysql数据库会拒绝访问。

可能还有别的原因,笔者只做了这几种情况总结,如果还有别的原因导致这个错误,欢迎指正并补充。

 

获取Java面试题请关注  Java蚂蚁  公众号

                                    

 

本文链接:https://my.lmcjl.com/post/14422.html

展开阅读全文

4 评论

留下您的评论.