python 连接mysql报错:NotSupportedError: Authentication plugin ‘caching_sha2_passwword

原因:

如果你的 MySQL 是 8.0 以上版本,密码插件验证方式发生了变化,早期版本为 mysql_native_password,8.0 版本为 caching_sha2_password,所以需要做些改变:
具体改变参考:https://blog.csdn.net/weixin_49319422/article/details/127449897

解决办法:

1.

先修改 my.ini 配置:

[mysqld]
default_authentication_plugin=mysql_native_password

重启mysql 服务

systemctl restart mysql

步骤1修改完后如果还不行,执行第2步;

2.

安装:

python -m pip install MySQL-connector-python

步骤1、步骤2 后基本可以使用了,如果还不行,执行步骤3;

3.

按如下代码修改:

myDb = connector.connect(
        host="localhost",
        user="root",
        passwd="******",
        database="test01",
        auth_plugin='mysql_native_password'
    )

猜你喜欢

转载自blog.csdn.net/weixin_49319422/article/details/127449701