#|python3.6+Django3.0 配置使用MySQL数据库错误 (mysqlclient 1.3.13 or newer is required)

错误场景 基于python3.6+Django3.0的项目配置MySQL时,安装pymysql的最高版本为0.9.3 ,为了导入MySQLdb时使用pymysql,在项目的__init__.py下添加以下代码:

import pymysql pymysql.install_as_MySQLdb()

运行出现错误
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

直接安装mysqlclient
pip install mysqlclient

报错
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

官方解释 PyMySQL的Github首页给出解释https://github.com/PyMySQL/mysqlclient-python
Linux
Note that this is a basic step. I can not support complete step for build for all environment. If you can see some error, you should fix it by yourself, or ask for support in some user forum. Don’t file a issue on the issue tracker.
You may need to install the Python 3 and MySQL development headers and libraries like so:
$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential # Debian / Ubuntu
% sudo yum install python3-devel mysql-devel # Red Hat / CentOS
Then you can install mysqlclient via pip now:
$ pip install mysqlclient
解决办法 一、
Ubuntu / Debian
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential # 如果是python3.7, 记得将python3-dev 改成 python3.7-devpip install mysqlclient

Red Hat / CentOS
sudo yum install python3-devel mysql-develpip install mysqlclient

【#|python3.6+Django3.0 配置使用MySQL数据库错误 (mysqlclient 1.3.13 or newer is required)】二、删除以下代码
import pymysql pymysql.install_as_MySQLdb()

    推荐阅读