1. 安装
    pip install pymysql

  2. 项目的init.py中

    import pymysql
    
    pymysql.install_as_MySQLdb()
    

可能遇到的错误

需要提前安装
yum -y install python3-devel openldap-devel

错误 : django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.3 or newer is required; you have 0.7.11

找到Python安装路劲下的Python36-32\Lib\site-packages\django\db\backends\mysql\base.py文件
将文件中的如下代码注释
if version < (1, 3, 3):
raise ImproperlyConfigured(“mysqlclient 1.3.3 or newer is required; you have %s” % Database.version)

AttributeError: ‘str’ object has no attribute ‘decode

修改decode ===》 encode
query = query.encode(errors=’replace’)

发表评论

邮箱地址不会被公开。