admin管理员组

文章数量:1618731

报错信息

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

常见解决方法一

1.检查mysql是否正常连接。IP,端口号,用户名,密码是否正确。至于如何检测,可以使用navicat 测试连接一下。如果连接的上,试试关闭防火墙,让别人连一下你自己的mysql,看看连的上嘛。

url: jdbc:mysql://localhost:3307/platform?characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowMultiQueries=true&zeroDateTimeBehavior=CONVERT_TO_NULL

username: root

password: 123

   

解决方法二

2.配置文件加上   &useSSL=false,记得改成false。这个是版本的问题,你可以看看别人的讲解。

解决方法三

3.我的navicat是能正常连接的。但是主机名只能写localhost才能连接,改成IP或者127.0.0.1就连接不上。

mysql中有个user表,将Host字段全部改为%,然后重启mysql。如果你没有安装navicat,可用命令提示符的修改方法,参考此文章:java.sql.SQLException: null, message from server: “Host ‘xxx.xxx.xxx.xxx‘ is not allowed to_凌抆莂的博客-CSDN博客

解决方法四 

4.我的上述的几个方法都使用了,但是还是不行。这个时候你就要看看你安装mysql版本是不是真的是你要的版本了。然后再看看配置文件(安装目录下一个叫“my.ini”的文件)。我最终是换了一下别人的配置文件才正常使用了。观察了一下配置文件,默认字符集不一致,还缺少了一些配置,具体不清楚是哪个导致的。

注意:安装目录、端口号 换成自己的,

本文标签: 顺序操作jdbcexceptionsmysql