Mac环境
1、安装mysql后,创建用户及数据库并授权
2、系统安装mysql-client
brew install mysql-client
3、python安装mysqlclient(在python虚拟环境中安装)
pip install mysqlclient
4、django项目的settings.py中修改:
DATABASES = {
'default': {
'ENGINE':'django.db.backends.mysql',
'HOST':'localhost',
'PORT':'3306',
'USER':'username',
'PASSWORD':'password',
'NAME':'dbname',
}
}
其他:
centos安装mysqlclient报错:OSError: mysql_config not found
先安装mysql-devel,再安装mysqlclient
yum install mysql-devel
pip3 install mysqlclient
网友评论