解决sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError) (2006, )问题
我遇到的问题
在使用flask框架时,远程连接服务器上的Mysql服务器失败
错误是:sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError) (2006, <NULL>)
解决办法
查询后应该是mysql8.0版本的加密方式为caching_sha2_password,python的MySQLdb连接暂不支持这种加密方式,所以修改mysql的加密方式
- 登录mysql
- 查询目前的加密方式
use mysql;
SELECT Host, User, plugin from user;
- 修改加密方式
alter user 'root'@'%' identified with mysql_native_password by 'your_password';
注意:
- your_password 为你的密码
- 如果你的 root 对应的Host不是 ‘%’,对应语句中的@后要修改为你的 Host 的值
- 使配置生效
flush privileges;
参考文章:
链接: MySQLdb.connect连接MySQL报错_mysql_exceptions.OperationalError: (2059, )
链接: https://blog.csdn.net/qq_45675449/article/details/106866700