在使用JDBC连接mysql时可能会遇到以下错误:

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

解决方法:

String url = "jdbc:mysql://192.168.xxx.xxx:3306/db";
此处的IP部分添加到hosts文件中,并使用hosts中设置的名称进行连接。
例:
String url = "jdbc:mysql://127.0.0.1:3306/db";
变为
String url = "jdbc:mysql://localhost:3306/db";
 
 
练习一下英语:
This error may encountered when using JDBC to connect Mysql:

  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

sulotions:

You need add target IP to your hosts file and name it.

make String url = "jdbc:mysql://192.168.xxx.xxx:3306/db";  be String url = "jdbc:mysql://hostname:3306/db";

example:

String url = "jdbc:mysql://127.0.0.1:3306/db";
change to
String url = "jdbc:mysql://localhost:3306/db";

MySql的Communications link failure解决办法的更多相关文章

  1. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 解决办法

    09:00:30.307 [http-8080-6] ERROR org.hibernate.transaction.JDBCTransaction -JDBC begin failed com.my ...

  2. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 解决

    感谢大佬:https://blog.csdn.net/a704397849/article/details/93797529 springboot + mybatis多数据库 + druid连接池配置 ...

  3. Java连接MySQL报错:CommunicationsException: Communications link failure

    现象: 报错:Exception in thread "main" com.mysql.cj.jdbc.exceptions.CommunicationsException: Co ...

  4. mysql 5.1超过默认8小时空闲时间解决办法(错误:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure)

    报错: MySQL第二天早上第一次连接超时报错, com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications lin ...

  5. jdbc 连接mysql Communications link failure的解决办法

    使用Connector/J连接MySQL数据库,程序运行较长时间后就会报以下错误: Communications link failure,The last packet successfully r ...

  6. 异常解决:Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    异常描述 这个异常通常有如下信息: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failu ...

  7. 解决Java程序连接mysql数据库出现CommunicationsException: Communications link failure错误的问题

    一.背景 最近在家里捣鼓一个公司自己搭建的demo的时候,发现程序一启动就会出现CommunicationsException: Communications link failure错误,经过一番排 ...

  8. 解决MySQL连接超时Communications link failure due to underlying exception

    最近在用一个MySQL的Java连接池的过程中,连接一晚上不释放,第二天就会造成超时的错误,查了一下原因,原来是因为MySQL默认的空闲等待时间是8个小时,一旦空闲超过8个小时,就会抛出异常.异常文本 ...

  9. 解决:com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure(真实有效)

    数据库连接失败 一.例如我在SpringBoot项目中使用了阿里的数据库连接池Driud. 有次在启动的时候,会报这样的错: Caused by: com.mysql.cj.exceptions.CJ ...

随机推荐

  1. 从0开始的Python学习017Python标准库

    简介 Python标准库使随着Python附带安装的,它包含很多有用的模块.所以对一个Python开发者来说,熟悉Python标准库是十分重要的.通过这些库中的模块,可以解决你的大部分问题. sys模 ...

  2. windows docker redis

    拉取docker docker pull hub.c.163.com/library/redis:latest 启动docker docker run -p 6379:6379 -d hub.c.16 ...

  3. Windows中通过命令行启动打开Service 管理工具

    经常需要打开Services 管理工具操控Service 的启动,停止. 通过控制面板 --> 管理工具 -->Service  太慢. 学到一个快捷方式. windows + R  启动 ...

  4. zabbix调用api检索方法

    环境 zabbix:172.16.128.16:zabbix_web:172.16.16.16/zabbix 用户名:Admin 密码:zabbix 获取的数据仅做参考,以Linux发送HTTP的PO ...

  5. mysql8.0.主从复制搭建

    搭建主从数据库 一.准备两台以上对的数据库 数据库1(主服务器):192.168.2.2 数据库2(从服务器):192.168.2.4           1.1      配置主服务器 .在 /et ...

  6. Docker: Jenkins与Docker的自动化CI/CD流水线实战

    什么是CI/CD 持续集成(Continuous Integration,CI):代码合并.构建.部署.测试都在一起,不断地执行这个过程,并对结果反馈.持续部署(Continuous Deployme ...

  7. 【java学习】实践中总结--持续更新中

    目录: 一些定义 配置环境 相关语法 1.一些定义 java中DO的含义: https://blog.csdn.net/canot/article/details/51698047 DAO 中包含了各 ...

  8. linux系统mysql-5.7 修改字符集

    起因:我在网上看修改mysql字符的文章时,都说配置/etc/mysql/my.cnf文件 然而我打开我上述的my.cnf文件时,发现里面的内容跟别人的不一样,我就觉得这个肯定不是正确的文件 经过我在 ...

  9. 毕业设计(1)基于MicroPython的大棚监测控制系统的程序设计与模型设计

    智慧农业就是将物联网技术运用到传统农业中去,运用传感器和软件通过移动平台或者电脑平台对农业生产进行控制,使传统农业更具有“智慧”.除了精准感知.控制与决策管理外,从广泛意义上讲,智慧农业还包括农业电子 ...

  10. springboot配置SSL自签名证书

    1.证书生成 每一个JDK或者JRE里都有一个工具,叫做:keytool,安装了jdk或jre之后,配置好JAVA环境之后,就可以直接在控制台使用该命令生成自签名证书: 在控制台输入: keytool ...