python连接MySQL NotSupportedError: Authentication plugin 'caching_sha2_password' is no supported

import mysql.connector
conn = mysql.connector.connect(user='root',password='password',
                               database='testpy')

报错:
mysql.connector.errors.NotSupportedError: Authentication plugin ‘caching_sha2_password’ is not supported

错误原因:

MySQL版本过高(用的是最新的8.0版本)

解决方法

加上参数 auth_plugin=‘mysql_native_password’

conn = mysql.connector.connect(user='root',password='password',
                               database='testpy',auth_plugin='mysql_native_password')

成功解决

你可能感兴趣的:(python,MySQL,数据库)