java - 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和:
- application.properties 中的 IP 地址正确
- 不知道为什么无法识别
- 端口号配置为 3306
- 我的数据库正在运行
- 服务器接受 tcp/ip 连接
- 不能用完连接,因为我可以同时连接 Workbench 和 shell
- 防火墙和代理配置为不阻止这些连接
有什么想法有什么问题吗?
编辑:我的 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
解决方案
推荐阅读
- c# - 为什么JsonResult需要同时实现IActionResult和IStatusCodeActionResult?
- javascript - (Javascript)如何遍历所有 JSON 对象但只获取特定值?
- python - 我如何翻译来自 Django 中的 JSON 文件的静态数据?
- ios - 如何在本机反应中使用缩放的后窗口从下到上为模态设置动画?
- python-3.x - 当 PythonOperator 出现错误“Negsignal.SIGKILL”时,气流 DAG 失败
- r - R:返回两个值的函数,用长垂直线 (|) 分隔
- python - 如何显示账面余额?
- javascript - 如何使用 React 在我正在渲染的 UI 中渲染从两个不同输入接收到的数据?
- windows-runtime - 如何使用 WinRT/C++ 在 WinUI3 中打开新窗口?
- java - Project Reactor 中的冷热定义是什么?