问题1. mysqlclient 安装
在 pycharm 项目的环境下,默认没有安装 mysqlclient 的话,当你运行
python manage.py makemigrations 这条命令是会提示你 安装mysqlclient,最简单的方法就是在Pycharm 右下角点击,如下图 (python or other),选择 Interpreter Settings..
然后在弹出的窗口做如下选择:
在搜索框中输入 mysql,选择下面的 mysqlclent,然后点安装,等待安装完成即可运行上述命令
问题2: 当运行命令 python manage.py migrate 时提示:
django.db.utils.OperationalError: (2059, "Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/Users/JohnDu/.conda/envs/Case001/lib/plugin/caching_sha2_password.so, 2): image not found")
主要就是mysql8.0的问题。
目前最新的mysql8.0对用户密码的加密方式为caching_sha2_password, django暂时还不支持这种新增的加密方式。只需要将用户加密方式改为老的加密方式即可。
解决步骤:
1.登录mysql,连接用户为root。
> mysql -u root -p
2.执行命令查看加密方式
> use mysql;
> select user, plugin from user where user='root';
3.执行命令修改加密方式
> alter user 'root'@'localhost' identified with mysql_native_password by 'yourpassword';
4.属性权限使配置生效
> flush privileges;
重设mysql8.0的加密方式后,再次启动django服务器就没有任何问题了。