django连接mysql数据库出现"Authentication plugin ‘caching_sha2_password’ cannot be loaded"错误的解决方法
最近在练习python(pycharm)+django搭建网站时,连接mysql数据库,出现错误:
django.db.utils.OperationalError: (2059, "Authentication plugin ‘caching_sha2_password’ cannot be loaded: …)
经过检查发现了问题的所在——主要是mysql8.0版本的问题。
(最近才从官网上面下载最新的mysql数据库,之前都是用的sql server数据库 0_0)
目前最新的mysql8.0数据库对用户密码的加密方式为caching_sha2_password, django暂时还不支持这种加密方式。所以只需将加密方式改为老版的即可。
解决方法:
在cmd命令中以root的身份登录mysql。
分别输入以下命令查看加密方式:
> use mysql;
> select user,plugin from user where user='root';
修改加密方式:
>alter user 'root'@'localhost' identified with mysql_native_password by 'password'
使更改的配置立即生效:
> flush privileges
更改成功后,再次启动django服务器,没有出现问题,成功!