问题
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