美文网首页
配置django的数据库mysql

配置django的数据库mysql

作者: 黑夜的眸 | 来源:发表于2018-07-21 20:21 被阅读0次

配置django的数据库为mysql:
setting.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'TxShop',
        'USER': 'root',
        'PASSWORD': 'root',
        'HOST': '127.0.0.1',
        'OPTIONS': {'init_command':'SET storage_engine=INNODB;'}
    }
}

但光配置这些还不够,还得安装mysqlclient。
使用pip安装mysqlclient报错:


running build_ext

    building '_mysql' extension

    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual

C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

解决方案:访问https://www.lfd.uci.edu/~gohlke/pythonlibs/

捕获.PNG
找到对应python版本的mysqlclient.
例如:通过python命令查到我是python3.6 win32
捕获.PNG
那么选择 mysqlclient‑1.3.13‑cp36‑cp36m‑win32.whl进行下载,之后在使用命令pip install (下载好的.whl绝对路径)安装,Done!
捕获.PNG
但依然报错:
捕获.PNG
django连接mysql数据库默认调用MySQLdb
python 3.6 中没有MySQLdb ,换成了pymysql,所以先要下载pymysql
(1)下载使用命令pip install pymysql
(2)配置驱动
在__init__.py中添加语句
import pymysql
pymysql.install_as_MySQLdb()

相关文章

网友评论

      本文标题:配置django的数据库mysql

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