MySQL——mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is...

python连接mysql时报错【mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not support】。
原因是:mysql8.0.11使用了Use Strong Password Encryption for Authentication即强密码加密。
通常的处理方法是:重装mysql【装更低版本的或者将Use Strong Password Encryption for Authentication改为Use Legacy Authentication Method(在Authentication Method中改)】
但这里还有一种更好的方案,那就是使用【pymysql】库来连接,代码如下:

    db_host = "localhost"
    db_username = "root"
    db_password = "123456"
    db_name = "database_name"
    conn = pymysql.connect(
        host=db_host,
        user=db_username,
        passwd=db_password,
        database=db_name,
    )

pymysql的详细教程见:http://www.runoob.com/python3/python3-mysql.html

你可能感兴趣的:(MySQL——mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is...)