1

I created a mysql docker image as:

docker run \
        --name mysql \
        -v /Users/pivdet/Downloads/backup/docker_mysql/conf.d:/etc/mysql/conf.d \
        -v /Users/pivdet/Downloads/backup/docker_mysql/initdb.d:/docker-entrypoint-initdb.d \
        -v /Users/pivdet/Downloads/backup/docker_mysql/data:/var/lib/mysql \
        -e MYSQL_ROOT_PASSWORD=piv123 \
        -p 3306:3306 \
        -d mysql

And started the server by docker start mysql

I could connect to the server in terminal: $ mysql -h127.0.0.1 -P3306 -uroot -ppiv123

But when I tried to connect it by using peewee:

import peewee

mysql_db = peewee.MySQLDatabase("websdl", host="127.0.0.1", port=3306, user="root", passwd="piv123")

if __name__ == "__main__":
    mysql_db.connect()

There's an error:

Traceback (most recent call last):
  File "models.py", line 6, in <module>
    mysql_db.connect()
...
peewee.OperationalError: (1045, u"Access denied for user 'root'@'172.17.0.1' (using password: NO)")

The user information of my db would be:

mysql> select Host, User from user;
+-----------+------------------+
| Host      | User             |
+-----------+------------------+
| %         | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
5 rows in set (0.01 sec)
pvd
  • 1,303
  • 2
  • 16
  • 31
  • Have you added your home IP address to the list of "Allowable Hosts" on your site's management portal? – Sandeep May 31 '18 at 03:17
  • @Sandeep I am curious why I typed my IP as `127.0.0.1` in peewee, but error show as `172.17.0.1`. – pvd May 31 '18 at 03:26
  • No idea! Check if you have installed database driver. If not, you can do so by following command: $ pip install pymysql – Sandeep May 31 '18 at 03:48
  • 1
    Can you connect using just plain old pymysql / mysql-python? – coleifer May 31 '18 at 20:07
  • 1
    I believe the user's issue had to do with mysql 8 and sha256 auth being incompatible with the python driver. – coleifer Jun 12 '18 at 21:01

0 Answers0