上海古都建筑设计集团,上海办公室装修设计公司,上海装修公司高质量的内容分享社区,上海装修公司我们不是内容生产者,我们只是上海办公室装修设计公司内容的搬运工平台

已解决The last packet sent successfully to the server was 0 milliseconds ago. The driver has not receiv

guduadmin11天前

注:此文章是在mysql8版本的前提下编写的。

在我们使用springcloud在连接mysql数据库时,有时会碰到如下这种异常:

    Exception in thread "main" 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:525)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
    at com.mysql.jdbc.MysqlIO.(MysqlIO.java:344)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2332)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
    at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:792)
    at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
    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:525)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
    at java.sql.DriverManager.getConnection(DriverManager.java:579)
    at java.sql.DriverManager.getConnection(DriverManager.java:243)
    at javaapplication3.JavaApplication3.main(JavaApplication3.java:32)

为此我上网查了不少资料,在这里小总结一下:

1. 连接url是否正确(自己看看useSSL是否为false):

已解决The last packet sent successfully to the server was 0 milliseconds ago. The driver has not receiv,第1张

2.数据库服务是否打开:

找到MySql服务:

已解决The last packet sent successfully to the server was 0 milliseconds ago. The driver has not receiv,第2张

3.网上最多解决的等待时间问题:(wait_timeout)

我使用的mysql版本为 8.0.27 ,在用网上的修改my.ini配置文件时 mysql会直接报错,启动不了,即使临时修改wait_timeout时间,也是一样会报错。目前 mysql8版本我找不到修改的方法。(也许是我笨蛋)

4.在依赖导入时mysql版本是否正确:

 上方的方法都实践过后如果依然报错,那么有极大可能是你在pom.xml文件中导入的mysql驱动与你自身安装的mysql版本不一致。

当写的项目是从外面copy进来的,那么就要仔细看mysql版本了,打开父工程的pom.xml文件:

已解决The last packet sent successfully to the server was 0 milliseconds ago. The driver has not receiv,第3张

可以看到版本不一致:

改成自身的版本:

已解决The last packet sent successfully to the server was 0 milliseconds ago. The driver has not receiv,第4张

子工程的版本都是从父工程中获取的,只要改这里就好了,版本对应上了,就没有再报错了。

如果帮到了你,还请留下一个小小的赞QAQ

 

 

 

网友评论

搜索
最新文章
热门文章
热门标签