2

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?

user13279307
  • 17
  • 1
  • 3
  • what is the error being outputted? This maybe caused by a couple of things. it maybe that your on site mysql does not allow connection from any IP address. This maybe a mysql configuration issue. please check that mysql allows the IP address of this spring boot. This is in the realms of mysql remote accessing – lemoncodes Apr 10 '20 at 15:12
  • Hi, yeah probably the host needs to whitelist your IP address to access or doesn't allow local access to it. And even if allowed, it would be better to not access from your local application and you could use a local mysql using docker. – Brother Apr 10 '20 at 15:46

2 Answers2

1

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.

so-random-dude
  • 15,277
  • 10
  • 68
  • 113
-2

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

user13279307
  • 17
  • 1
  • 3
  • Basic server security dictates that your database (or any other service's) port not be allowed through the firewall i.e. local connections only, nothing from outside. If you're having trouble establishing a connection over the internet to a server port running a specific service, first try and judge whether the port is even receiving traffic from the internet in the first place. – Meet K. Jun 17 '20 at 05:47