python使用mysql中遇到的问题记录

     python如果要使用mysql,需要第三方的模块MYSQL-python,但是使用pip install安装的时候很可能会遇到如下的问题,我的python版本是3.6.0,问题如下:

error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

按照这个提示,去下载Microsoft Visual Studio 14.0,下载安装后又提示:

_mysql.c(42): fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

简直是崩溃了,windows下使用python确实会出现比linux多的多的问题

在网上找了很多办法,最后发现一个解决方法,去如下网址下载对应的驱动https://pypi.python.org/pypi/mysqlclient/1.3.10


将下载的文件放到pip.exe同目录下,然后执行pip install mysqlclient-1.3.10-cp36-cp36m-win_amd64.whl

>pip install mysqlclient-1.3.10-cp36-cp36m-win_amd64.whl
Processing c:\python\python36\scripts\mysqlclient-1.3.10-cp36-cp36m-win_amd64.whl
Installing collected packages: mysqlclient
Successfully installed mysqlclient-1.3.10
检验一下mysql驱动模块是否安装成功

λ python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
没有报错,应该是安装成功了

我又在django的工程下验证了一下

首先需要在本地的mysql数据库中创建一个database:

create database mysite;

需要在我的工程下的settings.py中配置本地mysql的数据源

DATABASES = {
    'default': {
#        'ENGINE': 'django.db.backends.sqlite3',
#        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mysite',
        'USER': 'root',
        'PASSWORD': '123123',
        'HOST': '127.0.0.1',    # 默认
        'PORT': '3306',         # 默认

   }
}
然后执行命令
  
λ python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying sessions.0001_initial... OK
指令运行完后,mysql数据库中会自动创建一些django自带的表



问题解决!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值