Flask-SQLAlchemy PyMySQL - Access Denied Error

南楼画角 提交于 2019-12-12 04:15:46

问题


OS: RHEL Python Version: 3.6 SQLAlchemy Version: 1.1.10 PyMySQL Version: 0.7.11 MySQL Distrib: 5.7.17-13

import pymysql

conn = pymysql.connect(host='localhost', port=3306, user='testuser', passwd='###########', db='mysql')

cur = conn.cursor()

cur.execute("SELECT Host,User FROM user")

print(cur.description)

print()

for row in cur:
    print(row)

cur.close()
conn.close()

When I try to execute the above code I'm getting the following error message, but I'm still able to connect to mysql using the same account and password via command line.

pymysql.err.OperationalError: (1045, "Access denied for user 'testuser'@'127.0.0.1' (using password: YES)")

I tried searching all over the internet for this error message but I could not figure out the actual issue. I would really appreciate if anyone could help me fix this issue.


回答1:


I found the issue: The default auth plugin for MySQL 5.7 was sha256 which is not supported by PyMySQL. Changed it to mysql_native_password and that fixed the issue.



来源:https://stackoverflow.com/questions/44271782/flask-sqlalchemy-pymysql-access-denied-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!