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

Viewed 2801

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:

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

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

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

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

2 Answers

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.

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

Related