I am having an issue when using python mysql.connector module in a script. When I run to connect to a docker container running mysql v8 from my script it tries to connect to the wrong IP address. Below is the sample function:
import mysql.connector
def connect():
db = mysql.connector.connect(
host="172.17.0.2",
user="user",
passwd="password",
auth_plugin='mysql_native_password')
When this is ran, the following error is produced: mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'user'@'172.17.0.1' (using password: YES)
Here is the IP of the docker container that I am trying to connect to
IPAddress": "172.17.0.2"
What really makes this interesting is that I can connect to the database just fine with the mysql.connector when using in an interactive python session. See below
Python 3.7.2 (default, Jan 16 2019, 19:49:22)
[GCC 8.2.1 20181215 (Red Hat 8.2.1-6)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>> db = mysql.connector.connect(
... host="172.17.0.2",
... user="user",
... passwd="passwd",
... auth_plugin='mysql_native_password')
>>> mycursor = db.cursor()
>>> mycursor.execute("show databases")
>>> for x in mycursor: print(x)
...
('food',)
('information_schema',)
Here is the version of mysql-connector that I am running on Fedora 29
pip list |grep mysql-connector
mysql-connector-python 8.0.15
Here is docker version info as well
Client:
Version: 18.09.2
API version: 1.39
Go version: go1.10.6
Git commit: 6247962
Built: Sun Feb 10 04:13:54 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.2
API version: 1.39 (minimum version 1.12)
Go version: go1.10.6
Git commit: 6247962
Built: Sun Feb 10 03:47:25 2019
OS/Arch: linux/amd64
Experimental: false
Any thoughts on what would cause running this from a script to fail?