工具:python3.6+mysql8.0+pymysql
注意:python2.7以后的版本不再支持 MySQLdb这个模块。需要用pymysql,在命令行下安装的方法 输入pip install pymysql。
import pymysql conn = pymysql.Connect( host=‘127.0.0.1‘, port=3306, user=‘root‘, passwd=‘root‘, db=‘imooc‘, charset=‘utf8‘) cursor = conn.cursor()sql = ‘select * from students‘# print(cursor)cursor.execute(sql)print(cursor.fetchall()) cursor.close()conn.close() 执行这段代码出错 : pymysql.err.OperationalError: (1045, u"Access denied for user ‘root‘@‘localhost‘ (using password: No)")
新版mysql使用的caching_sha2_password认证方式,换成mysql_native_password就可以。
步骤是在cmd命令行连接mysql,
然后输入ALTER USER ‘root‘@‘localhost‘ IDENTIFIED WITH mysql_native_password BY ‘root‘;
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: N O)
原文地址:https://www.cnblogs.com/abdm-989/p/12113283.html
时间: 2024-10-07 19:45:55