peewee连接docker-mysql失败

时间:2018-05-31 03:05:09

标签: python mysql docker peewee

我创建了一个mysql docker镜像:

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

并按docker start mysql

启动服务器

我可以连接到终端中的服务器:$ mysql -h127.0.0.1 -P3306 -uroot -ppiv123

但是当我尝试使用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()

有一个错误:

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)")

我的数据库的用户信息是:

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)

0 个答案:

没有答案