Bootstrap

python 连接数据库出现报错“Authentication plugin 'caching_sha2_password' is not supported”

环境
  • python 3.7
  • mysql 8

代码如下:

import mysql.connector
mydb = mysql.connector.connect(
    host="localhost",
    user="root",
    passwd="zxcv1234"
)

print(mydb)

拿出来之后直接报错:不支持身份验证插件“ caching_sha2_password”,
解决办法:声明验证方式即可

import mysql.connector

conn = mysql.connector.connect(
	host="localhost",
    user="root",
    passwd="zxcv1234",
    auth_plugin='mysql_native_password'
)

print(conn)
;