今天一个程序老旧没用了,今天想用下,结果原先跑的好好的程序,突然报错了,报错如下:
stackoverflow上解释道:
Are you actually using the long-dead connector
MySQL-python
, akaMySQLdb
? If so, that only works with MySQL 5.x (and was only ever fully tested with 5.0).
原来是我的flask用的mysqldb驱动已经太老,已经不能支持最新的Mysql 8,所以这里将数据库驱动换成更新的pymysql
(当然如果没有安装要安装一下pip install pymysql
)
修改config.py
DIALECT = ‘mysql‘
DRIVER = ‘pymysql‘ # 这里改成pymysql驱动
USERNAME = ‘root‘
PASSWORD = ‘root‘
HOST = ‘127.0.0.1‘
PORT = ‘3306‘
DATABASE = ‘xx‘
SQLALCHEMY_DATABASE_URI = "{}+{}://{}:{}@{}:{}/{}?charset=utf8".format(DIALECT, DRIVER, USERNAME, PASSWORD, HOST, PORT, DATABASE)
SQLALCHEMY_TRACK_MODIFICATIONS = False
欸,以后不要稀里糊涂地复制代码了