Vibhu Banga
Vibhu Banga

Reputation: 11

Latest Docker image throws error connecting to MYSQL

I have been trying to do a POC to use Liquibase docker image for connecting to MYSQL instance and publish DB changes. I have been following these article

https://docs.liquibase.com/workflows/liquibase-community/using-liquibase-and-docker.html https://hub.docker.com/r/liquibase/liquibase https://github.com/Inkimar/liquibase-example - Sample Repo

However I am always getting the below error ->

**Connection could not be created to jdbc:mysql://localhost:3306/denmark with driver 
com.mysql.cj.jdbc.Driver.  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.
liquibase.exception.CommandExecutionException: liquibase.exception.LiquibaseException: 
Unexpected error running Liquibase: liquibase.exception.DatabaseExcepti
on: liquibase.exception.DatabaseException: Connection could not be created to 
jdbc:mysql://localhost:3306/denmark with driver com.mysql.cj.jdbc.Driver.  
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 liquibase.command.CommandScope.execute(CommandScope.java:163)
at liquibase.integration.commandline.CommandRunner.call(CommandRunner.java:51)
at liquibase.integration.commandline.CommandRunner.call(CommandRunner.java:21)
at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
at picocli.CommandLine.access$1300(CommandLine.java:145)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent
(CommandLine.java:2358)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
at picocli.CommandLine.execute(CommandLine.java:2078)
at liquibase.integration.commandline.LiquibaseCommandLine.lambda$execute$1
(LiquibaseCommandLine.java:336)
at liquibase.Scope.child(Scope.java:189)
at liquibase.Scope.child(Scope.java:165)
at liquibase.integration.commandline.LiquibaseCommandLine.execute
(LiquibaseCommandLine.java:301)
at liquibase.integration.commandline.LiquibaseCommandLine.main
(LiquibaseCommandLine.java:90)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at liquibase.integration.commandline.LiquibaseLauncher.main(LiquibaseLauncher.java:91)**

Any luck or pointer is highly appreciated. I have tried using MYSQL 5.7 and 8.x version but no luck.

Upvotes: 1

Views: 749

Answers (1)

Erin Kolp
Erin Kolp

Reputation: 21

**Connection could not be created to jdbc:mysql://localhost:3306/denmark with driver

I'm guessing that you're running two containers, 1 running Liquibase, and 1 running MySQL. Is that correct? You can't use "localhost" inside the Liquibase container, as each has a loopback interface. Forward the port (-p 3306:3306) when you run the container and use your local network address (ie. 192.168.10.x, for example).

The other option is to spin it up with docker-compose (so they're on the same virtual network) and use the hostnames to connect.

Upvotes: 2

Related Questions