com.mysql.cj.jdbc.exceptions.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 com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
... ...
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
这个问题解决方法可能不为一,因为我看了其他的方案,我的不行,但有的人就解决了,在此我写出我的解决方法。
重新创建项目,因为我重新创建项目好了,个人感觉这个可能是我在按照springboot初始化器生成了高版本的项目,然后导入完高版本的依赖之后,我有用低版本的pom.xml覆盖了高版本的pom.xml。由此可能出现了某些不可知的问题,后来又重新建项目,在新建完项目之后,立刻替换了那个pom.xml,可能会按照此pom来到依赖,运行之后没有出问题,正常运行。
我这个可能会很麻烦,但也不一定会解决你的问题,最好作为最后方案
还有的是这个问题,但cause by中出现了没有什么协议,这个需要在mysql的URL中添加上
&useSSL=false
还有一种就是看看
mysql服务有没有启动
再增加一种就是:如果在虚拟机中安装了docker,之后又在docker中安装了mysql,可以试试重启以下mysql