Error connect mysql via TCP by traefik

We are running a mysql container on a VM(192.168.12.86).

CONTAINER ID   IMAGE   COMMAND  CREATED       STATUS       PORTS                    NAMES
e50   mysql:5.7.22   "docker-entr"   8 hours ago   Up 8 hours   0.0.0.0:3306->3306/tcp   dev-mysql

We wants to connect that mysql container via traefik. We are running traefik on a separate VM (192.168.12.81).

In our traefik.toml -

defaultEntryPoints = ["http", "https"]

[entryPoints]
  [entryPoints.mysql]
    address = ":3306"

And on dynamic.toml -

[tcp]
  [tcp.routers]
    [tcp.routers.to-database]
      entryPoints = ["mysql"]
      rule = "HostSNI(`*`)"
      service = "database"

  [tcp.services]
    [tcp.services.database.loadBalancer]
      [[tcp.services.database.loadBalancer.servers]]
        address = "192.168.12.86:3306"

But we couldn't connect mysql server. Getting this error -

2013 - Lost connection to MySQL server at 'waiting for initial communication packet', system error: 110 "Connection timed out"

Hello @ipasa

You have inspired me and this morning I deployed MySQL on one of my test clusters and exposed it via Traefik TCP Router. Your configuration seems to be correct because you use HostSNI(*) without TLS and it means that network traffic should correctly forward to the entry point. See that "PR"

However, you didn't post how you deployed Traefik (if it is a container or a standalone instance) but you could first check whether 192.168.12.86:3306 is reachable from the host where Traefik is deployed. Seems that the client didn't reach the MySQL instance because of the timeout, so seems that it is a network connectivity issue.

Please also make sure that you create the appropriate user who can connect to the MySQL server, for test purposes you can create that can be allowed to connect from any host ('newuser'@'%')

Hope that helps,

1 Like