Java/Spring连接MySQL出现Communications link failure解决

2021-12-01 401点热度 0人点赞 5条评论

今天启动一个交接的项目,发现启动报错,如下错误提示:

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:404)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:981)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:339)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253)

解决办法

通过研究,发现如下解决办法,把mysql配置连接的url增加如下参数:

autoReconnect=true&allowPublicKeyRetrieval=true

完整的url例子:

url: jdbc:mysql://localhost:3306/dbname?useUnicode=true&useSSL=false&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowMultiQueries=true&autoReconnect=true&allowPublicKeyRetrieval=true

 

admin

这个人很懒,什么都没留下

文章评论

  • Terese Fisher

    Give your new site a boost, submit your site now to our free directory and start getting more clients

    2022-03-29
  • Pedro Cheshire

    Add your site to all 35 of our business directories with one click here-

    2022-04-03
  • Hayley Rumsey

    Add your site to all 35 of our business directories with one click here

    2022-05-12
  • Silvia Gerald

    Good job on the new site! Now go ahead and submit it to our free directory here

    2022-05-24
  • Marilyn Smithies

    I was wondering if you wanted to submit your new site to our free business directory?

    2022-06-10
  • 您需要 登录 之后才可以评论