com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

报错信息

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”的文件)。我最终是换了一下别人的配置文件才正常使用了。观察了一下配置文件,默认字符集不一致,还缺少了一些配置,具体不清楚是哪个导致的。

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tengyuxin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值