Why do I get InterfaceError when connecting to MySql Server in python in a docker container?

  database, database-connection, docker, mysql, python

I run the code from https://github.com/aiordache/demos/tree/master/dockercon2020-demo which is from some official docker blog.

I get

mysql.connector.errors.InterfaceError
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'db:3306' (111 Connection refused)

I even tried some solutions like

self.cursor.execute('GRANT ALL PRIVILEGES ON *.* TO 'root'@'%')

or putting in the port number:

    self.connection = mysql.connector.connect(
            user=user, 
            password=pf.read(),
            host=host,
            database=database,
            port='3306'
            auth_plugin='mysql_native_password'
        )

I dunno whats wrong.

Source: Docker Questions

LEAVE A COMMENT