0

Running Windows 10 docker desktop version Code is working fine connecting to an RDS instance . but gives below error while connecting to a hosted db (has to be on VPN)

docker run raasapp:test
Exception in thread "main" 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.
        at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
        at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
        at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
        at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
        at java.sql.DriverManager.getConnection(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:247)
        at com.test.RDSConnectionTest.getConnection(RDSConnectionTest.java:18)
        at com.test.RDSConnectionTest.main(RDSConnectionTest.java:50)
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
Shadow
  • 33,525
  • 10
  • 51
  • 64
uman dev
  • 409
  • 1
  • 5
  • 12
  • In your my.cnf make sure you have `bind_address=0.0.0.0` so MySQL will listen on all interfaces. By default it only listens to localhost. – Cfreak Jun 25 '20 at 02:43
  • you mean on the mySQL server? – uman dev Jun 25 '20 at 02:44
  • See this answer: https://stackoverflow.com/questions/2482234/how-do-i-find-the-mysql-my-cnf-location – Cfreak Jun 25 '20 at 02:47
  • changes to remote mySQL server ini file is not an option. is there an alternate solution on client side short term. – uman dev Jun 25 '20 at 02:51
  • There is absolutely nothing in the exception list you provided that would tell us what went wrong. You have to get the underlying error message, such as connection refused. – Shadow Jun 25 '20 at 02:53
  • Communication link failure errors can rarely be resolved on the client alone. – Shadow Jun 25 '20 at 02:54
  • driver not received any packets from server. Caused by: java.net.UnknownHostException: : Name or service not known at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:132) at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65) ... 10 more – uman dev Jun 25 '20 at 02:57
  • I thought by "host" you meant the docker host as in MySQL was running locally. Sounds like your docker container can't talk to the internet. – Cfreak Jun 25 '20 at 03:00
  • ok. more info on the issue. mysql server is running onsite . I am able to talk to it from a legacy java app. but when i dockerize it it gives communication failure error. unknown host. this is not a docker issue since i am able to connect to RDS . issue is with connecting to onsite mysql server only. – uman dev Jun 25 '20 at 03:07
  • Well, this is not a mysql issue either. The client cannot resolve the host name. – Shadow Jun 25 '20 at 03:44
  • is `.cj` working ? you can try to change the driver without `.cj` – Cyrille Con Morales Jun 25 '20 at 07:02
  • editing windows hosts file for dns entry solved the issue. – uman dev Jul 01 '20 at 05:53

0 Answers0