我可以毫无问题地在MySQL中访问我的mysql连接,但是当我使用PyMySQL时,我收到了错误:
pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")
我使用与我常规MySQL连接相同的凭据和密码。
这是我的代码:
import pymysql.cursors
# Connect to the database.
connection = pymysql.connect(host='localhost',
user='root',
password='root',
db='skolen',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
print ("connect successful!!")
try:
with connection.cursor() as cursor:
# SQL
sql = "SELECT * FROM Skolen.hut "
# Execute query.
cursor.execute(sql)
print ("cursor.description: ", cursor.description)
print()
for row in cursor:
print(row)
finally:
# Close connection.
connection.close()