python连接mysql的配置过程

1.确保已经安装好python和Django

2.创建django项目

3.打开setting.py配置文件

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'blog', //数据库名称
        'USER': 'root', //用户名
        'PASSWORD': '123456', //密码
        'HOST': 'localhost', //地址
        'PORT': '3306', //端口
    }
}

4.查看是否安装有pymysql,若未安装,使用pip install pymysql

5.进入django项目根目录,运行程序:

python manage.py runserver
程序会显示如下错误:

 _mysql.c(29): fatal error C1083: 无法打开包括文件: “mysql.h”: No such file or directory
    error: command 'D:\\vs2015\\VC\\BIN\\amd64\\cl.exe' failed with exit status 2

这是驱动的问题,往下面的链接中下载MySQL-python-1.2.3.win-amd64-py2.7.exe

链接地址:http://www.codegood.com/archives/129   (注意下载过程中要根据系统版本进行下载安装)

6.执行第五步,若显示如下,证明配置成功

D:\pythonPro\new_file\djangoBlog>python manage.py runserver
Performing system checks...

2017-12-20 10:06:30,566 [utils:execute] [DEBUG]- (0.000) SELECT @@SQL_AUTO_IS_NULL; args=None
2017-12-20 10:06:30,566 [utils:execute] [DEBUG]- (0.000) SELECT VERSION(); args=None
System check identified no issues (0 silenced).
2017-12-20 10:06:30,657 [utils:execute] [DEBUG]- (0.000) SHOW FULL TABLES; args=None
2017-12-20 10:06:30,667 [utils:execute] [DEBUG]- (0.000) SELECT `django_migrations`.`app`, `django_migrations`.`name` FROM `django_migrations`; args=()
December 20, 2017 - 10:06:30
Django version 1.11.5, using settings 'djangoBlog.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
2017-12-20 10:06:36,788 [basehttp:log_message] [INFO]- "GET / HTTP/1.1" 200 445
2017-12-20 10:06:36,957 [basehttp:log_message] [INFO]- "GET /get_count HTTP/1.1" 301 0
2017-12-20 10:06:36,957 [basehttp:log_message] [INFO]- "GET /get_articles HTTP/1.1" 301 0
2017-12-20 10:06:36,957 [basehttp:log_message] [INFO]- "GET /get_rightbox_content HTTP/1.1" 301 0



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章