美文网首页
nginx+uwsgi+django2.2+python3.6+

nginx+uwsgi+django2.2+python3.6+

作者: 邪恶的奥伯伦 | 来源:发表于2019-05-24 17:57 被阅读0次

mysql 用docker,docker pull mysql
django用最新的2.2
python ubuntu18.04自带的3.6

django的mysql驱动选择mysqlclient 不选pyMySQL是因为需要改python代码,docker里改麻烦。

直接安装 mysqlclient 会报错OSError: mysql_config not found
需要先安装依赖:
ubuntu:

sudo apt-get install libmysqlclient-dev
if libmysqlclient-dev not exists, try 
apt-get install -y default-libmysqlclient-dev

yum:

yum install mysql-devel

MacOS:

brew install mysql-client
#mysql-client is not on the `PATH` by default
export PATH="/usr/local/opt/mysql-client/bin:$PATH"
#openssl is not on the link path by default
export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/opt/openssl/lib/"
#Then I could pip wheel mysqlclient / pip install mysqlclient successfully

启动django 报错django.db.utils.OperationalError: (2002, "Can't connect to local MySQL

server through socket '/var/run/mysqld/mysqld.sock' (2)")
需要把mysql host 从localhost 改成127.0.0.1

或者

如果是docker-compose启动的db需要在 host = [docker-compose DB service name]

字符集设置为utf8
修改db字符集 alter database ss_db default character set utf8;
修改表字符集 alter table auth_permission convert to character set utf8;

相关文章

网友评论

      本文标题:nginx+uwsgi+django2.2+python3.6+

      本文链接:https://www.haomeiwen.com/subject/yqnwzqtx.html