我们能否为外部MySQL服务器配置spring.datasource.url?

huangapple go评论87阅读模式
英文:

Can we configure spring.datasource.url for external mysql server

问题

以下是翻译好的部分:

对于我的 Springboot 项目,我无法连接到我在一个站点上托管的 MySQL。使用本地 MySQL(Workbench)可以正常工作,但是当我将 localhost 的 URL 替换为主机的 URL 时,它不起作用,并且我收到以下错误消息:

com.mysql.cj.jdbc.exceptions.CommunicationsException: 通信链接失败

最后一个成功发送到服务器的数据包距离现在 0 毫秒。驱动程序未从服务器接收到任何数据包。

以下是我的应用程序属性中的代码:

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/word?
spring.datasource.username=root
spring.datasource.password=root

我用我的数据库主机替换了以下代码行:

spring.datasource.url=jdbc:mysql://db.example.net:3306/word?
英文:

For my Springboot project I can't connect to a mysql that I had hosted on a site. With a local mysql (workbench) it works well but when I replace the localhost url with that of the host it does not work and I have the following error message:
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.

here is my code in application properties:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/word?
spring.datasource.username=root
spring.datasource.password=root

<!-- end snippet -->

I replace the following line of code with my Database Host:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

spring.datasource.url=jdbc:mysql://db.example.net:3306/word?

<!-- end snippet -->

spring.datasource.url=jdbc:mysql://db.example.net:3306/word?

答案1

得分: 1

可以是很多原因:

  1. 机器上基于IPTables/firewalld的防火墙设置
  2. 网络上的防火墙
  3. 或者简单地目标IP无法访问
  4. 如果前面的3个步骤都正确,可能是MySQL服务器端配置不允许远程连接。将该选项修改(可能需要重启MySQL服务)

我会从ping数据库IP地址开始。如果可以访问,就可以排除第3种情况。然后我会查找上述的MySQL服务器端配置。

英文:

It could be many things

  1. IPTables/firewalld based firewall on either machines
  2. Firewall on the network
  3. Or simply IP is not reachable
  4. If all the above 3 is done right then it could be a config on MySQL server side to not accept remote connections. Flip that flag (and possibly restart the MySQL service)

I would start from pinging the DB IP. If that's accessible you can rule out the line number 3. Then next I would look for the aforementioned config on mysql server side.

答案2

得分: -2

我刚收到了一条来自支持部门的消息,他们不允许来自任何IP地址的连接。感谢您的回答!

英文:

I just received a message from the support, they don't allow connection from any IP address. Thanks for answers!

huangapple
  • 本文由 发表于 2020年4月10日 22:26:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/61142390.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定