英文:
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
可以是很多原因:
- 机器上基于IPTables/firewalld的防火墙设置
- 网络上的防火墙
- 或者简单地目标IP无法访问
- 如果前面的3个步骤都正确,可能是MySQL服务器端配置不允许远程连接。将该选项修改(可能需要重启MySQL服务)
我会从ping数据库IP地址开始。如果可以访问,就可以排除第3种情况。然后我会查找上述的MySQL服务器端配置。
英文:
It could be many things
- IPTables/firewalld based firewall on either machines
- Firewall on the network
- Or simply IP is not reachable
- 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!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论