django2.2 mysql8.0 mysqlclient

我怕爱的太早我们不能终老 提交于 2019-12-05 02:01:46

django2.2 官方mysql

django mysql 支持

MySQL DB API Drivers¶
MySQL has a couple drivers that implement the Python Database API described in PEP 249:

mysqlclient is a native driver. It’s the recommended choice.
MySQL Connector/Python is a pure Python driver from Oracle that does not require the MySQL client library or any Python modules outside the standard library.
These drivers are thread-safe and provide connection pooling.

In addition to a DB API driver, Django needs an adapter to access the database drivers from its ORM. Django provides an adapter for mysqlclient while MySQL Connector/Python includes its own.

mysqlclient¶
Django requires mysqlclient 1.3.13 or later.
#安装依赖
brew install mysql-connector-c

#安装mysqlcinet
pip install mysqlclinet  #会报错
#错误信息
Command "python setup.py egg_info" failed with error code 1 in
/private/var/folders/0h/jn4vphd94wsf0sl01jb74p200000gn
/T/pip-build-75a5emrb/mysqlclient/

#修改配置文件
vim /usr/local/Cellar/mysql-connector-c/6.1.11/bin/mysql_config

# 源内容
# Create options  
libs="-L$pkglibdir"
libs="$libs -l "

#新内容,8.0 中不需要
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"


#~/.zshrc 增加openssl环境变量
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
# 重新安装mysqlcinet
pip install mysqlclinet
#最后一步
最后在项目的__init__.py配置 import MySQLdb

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because openssl/libressl is provided by macOS so don't link an incompatible version.

If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
(drf3) ➜  SanQingApp git:(master) ✗ pip list
Package                 Version   
----------------------- ----------
aliyun-python-sdk-core  2.13.11   
amqp                    2.5.2     
asgiref                 3.2.3     
bcrypt                  3.1.7     
billiard                3.6.1.0   
celery                  4.3.0     
certifi                 2019.9.11 
cffi                    1.13.2    
chardet                 3.0.4     
coreapi                 2.3.3     
coreschema              0.0.4     
cryptography            2.8       
Django                  2.2       
django-celery-results   1.1.2     
django-crispy-forms     1.8.0     
django-debug-toolbar    2.1       
django-extensions       2.2.5     
django-filter           2.2.0     
django-guardian         2.1.0     
django-redis            4.10.0    
djangorestframework     3.10.3    
djangorestframework-jwt 1.11.0    
drf-yasg                1.17.0    
Fabric3                 1.14.post1
gunicorn                20.0.0    
idna                    2.8       
importlib-metadata      0.23      
inflection              0.3.1     
itypes                  1.1.0     
Jinja2                  2.10.3    
jmespath                0.9.4     
kombu                   4.6.6     
Markdown                3.1.1     
MarkupSafe              1.1.1     
more-itertools          7.2.0     
mysqlclient             1.4.5     
packaging               19.2      
paramiko                2.6.0     
pip                     19.3.1    
pycparser               2.19      
pycrypto                2.6.1     
pycryptodome            3.9.4     
PyJWT                   1.7.1     
PyMySQL                 0.9.3     
PyNaCl                  1.3.0     
pyparsing               2.4.5     
pytz                    2019.3    
redis                   3.3.11    
requests                2.22.0    
ruamel.yaml             0.16.5    
ruamel.yaml.clib        0.2.0     
setuptools              41.6.0    
six                     1.13.0    
sqlparse                0.3.0     
uritemplate             3.0.0     
urllib3                 1.25.7    
vine                    1.3.0     
wheel                   0.33.6    
xmltodict               0.12.0    
zipp                    0.6.0    

正常使用,去掉pymysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!