首页 > 解决方案 > MySQL CommunicationsException:通信链接失败

问题描述

我已经看到了很多关于这个问题的话题,但不幸的是我无法解决我的问题。我已经在我的服务器(CentOS 7)上安装了 MySQL,我可以通过 shell 或 MySQL Workbench 连接我的数据库,但是当我尝试运行我的 Java 应用程序时,我会收到如下错误:

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.

Caused by: java.net.UnknownHostException: (my server's ip): nodename nor servname provided, or not known

防火墙或代理无法阻止连接,因为我可以通过 Workbench 或 shell 与 DB 连接。此外,我已经关注了这个主题:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure和:

  1. application.properties 中的 IP 地址正确
  2. 不知道为什么无法识别
  3. 端口号配置为 3306
  4. 我的数据库正在运行
  5. 服务器接受 tcp/ip 连接
  6. 不能用完连接,因为我可以同时连接 Workbench 和 shell
  7. 防火墙和代理配置为不阻止这些连接

有什么想法有什么问题吗?

编辑:我的 application.properties 配置

#Database - deployment
spring.datasource.url=jdbc:mysql://xxx.xx.xxx.xxx/mydbname?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Europe/Warsaw
spring.datasource.username=mylogin
spring.datasource.password=mypassword

#Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto=create
spring.jpa.database=mysql
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

标签: javamysqllinuxcentos

解决方案


推荐阅读