一、运行项目报错信息如下:

File "/home/pyvip/.virtualenvs/myblog/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 36, in <module>
 raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

mysql版本太低了,进入/home/pyvip/.virtualenvs/myblog/lib/python3.6/site-

packages/django/db/backends/mysql/base.py,用vim将其打开


在这里插入图片描述

35,36行需要注释掉,然后就不会因为版本而报错,在末行模式下输入wq保存退出


在这里插入图片描述

二、再次运行项目报如下错误

File "/home/pyvip/.virtualenvs/myblog/lib/python3.6/site-packages/django/db/backends/mysql/operations.py", line 146, in last_executed_query
 query = query.decode(errors='replace')
AttributeError: 'str' object has no attribute 'decode'

使用vim进入/home/pyvip/.virtualenvs/myblog/lib/python3.6/site-packages/django/db/backends/mysql/operations.py中
在第146行中,将decode改为encode即可


在这里插入图片描述

此时再次运行项目,可以看到运行成功了!!!证明mysql数据库连接成功!


总结