Python连接MySQL报错:mysql.connector.errors.NotSupportedError: Authentication plugin ‘caching_sha2_password’ is not supported
Python连接MySQL数据库报错:mysql.connector.errors.NotSupportedError: Authentication plugin ‘caching_sha2_password’ is not supported

这个错误出现的原因是在mysql8之前的版本中加密规则为mysql_native_password,而在mysql8以后的加密规则为caching_sha2_password。
解决办法:
添加一句语句(auth_plugin=‘mysql_native_password’),添加位置如下代码:

import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="123",
database="mybase",
auth_plugin='mysql_native_password'
)
mycursor = mydb.cursor()
mycursor.execute("SHOW TABLES")
- 致谢
若对大家有用,感谢点赞或评论;若有不足或补充之处,也感谢大家评论进行指正,后期我将对本文进行补充完善。相信这是互相进步的开始!

针对Python连接MySQL8.0及更高版本时出现的'caching_sha2_password'认证插件不支持错误,本文提供了解决方案,通过设置auth_plugin参数为'mysql_native_password'来兼容旧版加密规则。
9679





