Flask连接Windows版MySQL时出现的问题记录
文章目录
1.ModuleNotFoundError: No module named ‘MySQLdb’
在Flask中连接MySQL时出现ModuleNotFoundError: No module named 'MySQLdb'
错误,需要在配置SQLALCHEMY_DATABASE_URI时加上pymysql:app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:[email protected]/你的数据库名'
如果没有pymysql话的需要用pip进行安装。
原因为:MySQLdb只支持Python2.*,还不支持3.*,可以用pymysql代替。
参考链接:https://blog.****.net/qq_25046261/article/details/78991442
2.问题 1336 Incorrect string value: '\xD6\xD0\xB9\xFA\……
具体报错为:default.py:470: Warning: (1366, "Incorrect string value: '\xD6\xD0\xB9\xFA\xB1\xEA...' for column 'VARIABLE_VALUE' at row 479")
原因可能是哪一部分的驱动的编码格式有问题。
换成使用mysqlconnector就可以了,如下:app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+mysqlconnector://root:[email protected]/database'
参考链接:https://segmentfault.com/a/1190000010596306
3.python3.5连接mysql8.0.13 出现 caching_sha2_password错误。
具体报错为:mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported
原因是因为mysql8.0.11使用了Use Strong Password Encryption for Authentication即强密码加密。
解决方法有两种:1:重新配置mysql,将Use Strong Password Encryption for Authentication改为Use Legacy Authentication Method(在Authentication Method中改) 2:因为python3.5以下不支持caching_sha2_password,可使用python3.6进行连接。
我暂时不想升级到3.6,所以就重新配置MqSQL,下面是流程:
1.运行开始菜单中的
mysql installer
2.对MySQL Server 进行Reconfigure
3.在这一步中将密码模式换成下面这个legacy Authentication Method,就ok了
参考链接:https://blog.****.net/sinat_36188088/article/details/81174509
感谢以上各位大神。