解决“NotSupportedError: Authentication plugin ‘caching_sha2_password‘ is not supported”

NotSupportedError: Authentication plugin ‘caching_sha2_password’ is not supported

着急的话,将数据库连接代码更换:

engine = create_engine('mysql+mysqlconnector://用户名:密码@localhost:3306/test?auth_plugin=mysql_native_password')

最近在弄flask通过SqlAlchemy操作数据库,在连接数据库配置文件整好,进行使用增删改除时,报出错误:
NotSupportedError: Authentication plugin ‘caching_sha2_password’ is not supported

原因:
MySQL从8.0版本开始使用的默认加密认证方式就是:
caching_sha2_password 而不是 mysql_native_password

解决方法:
将连接代码改为:
engine = create_engine('mysql+mysqlconnector://用户名:密码@localhost:3306/test?auth_plugin=mysql_native_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")

解决不了,可以一起讨论下,解决后就继续干活吧!!!

Guess you like

Origin blog.csdn.net/qq_47122804/article/details/121105562