python3使用Django框架连接mysql(python3+Django+MySQL+pymysql)
2016-12-10 00:23
966 查看
改掉系统默认的sqlite3数据库,
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
'ENGINE': 'django.db.backends.mysql',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'NAME':'djangoDB',
'USER':'root',
'PASSWORD':'123456',
'port':'3306',
}
}
然后启动报错,
ImportError: No module named 'MySQLdb'
据说要装MySQL-python
可是MySQL-python一直无法安装成功。
又报错ImportError: No module named 'ConfigParser'
因为python3中叫做configparser,是小写。
好吧,听说不用MySQL-python可以用pymsql代替,然后就赶紧下载pip install pymysql
然后再启动,还是不行啊,还是ImportError: No module named 'MySQLdb'
百度了下,看这篇文章http://www.jianshu.com/p/82781add8449
加了之后就好了。
这里说下MySQL-python吧。
MySQL-python的解释看官方说法
MySQLdb is an interface to the popular MySQL database server for Python. The design goals are:
Compliance with Python database API version 2.0 [PEP-0249]
Thread-safety
Thread-friendliness (threads will not block each other)
MySQL-3.23 through 5.5 and Python-2.4 through 2.7 are currently supported. Python-3.0 will be supported in a future release. PyPy is supported.
说白了就是连接mysql的python接口,有了他就可以用python来操作数据库了。类似java的JDBC那一套东西把。
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
'ENGINE': 'django.db.backends.mysql',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'NAME':'djangoDB',
'USER':'root',
'PASSWORD':'123456',
'port':'3306',
}
}
然后启动报错,
ImportError: No module named 'MySQLdb'
据说要装MySQL-python
可是MySQL-python一直无法安装成功。
又报错ImportError: No module named 'ConfigParser'
因为python3中叫做configparser,是小写。
好吧,听说不用MySQL-python可以用pymsql代替,然后就赶紧下载pip install pymysql
然后再启动,还是不行啊,还是ImportError: No module named 'MySQLdb'
百度了下,看这篇文章http://www.jianshu.com/p/82781add8449
加了之后就好了。
这里说下MySQL-python吧。
MySQL-python的解释看官方说法
MySQLdb is an interface to the popular MySQL database server for Python. The design goals are:
Compliance with Python database API version 2.0 [PEP-0249]
Thread-safety
Thread-friendliness (threads will not block each other)
MySQL-3.23 through 5.5 and Python-2.4 through 2.7 are currently supported. Python-3.0 will be supported in a future release. PyPy is supported.
说白了就是连接mysql的python接口,有了他就可以用python来操作数据库了。类似java的JDBC那一套东西把。
相关文章推荐
- Python3.5-Django1.11 使用pymysql 连接mysql
- django1.6.x(python3.3)使用pymysql连接mysql
- python3.5下django2.0使用pymysql连接mysql
- Python进阶(二十三)-Django使用pymysql连接MySQL数据库做增删改查
- flask框架在python中通过sqlalchemy+pymysql连接mysql
- Python 3.2: 使用pymysql连接Mysql
- django中运行连接mysql(使用pymysql代替MySQL_db)
- Linux 下安装Python框架django建立与mysql的连接
- Python django使用多进程连接mysql错误的解决方法
- python3.5 中Django框架连接mysql
- 基于Python3.6使用Django框架连接mysql数据库的驱动模块安装解决办法
- python3.6 使用 pymysql 连接 Mysql 数据库及 简单的增删改查操作
- python3.4使用PyMySQL来连接mysql
- Python 3.2: 使用pymysql连接Mysql
- Python3中使用PyMySQL连接Mysql
- Python3.4使用pymysql连接MySQL
- Python 使用pymysql连接MySQL
- python3.6 使用 pymysql 连接 Mysql 数据库及 简单的增删改查操作
- 在 Windows Azure 网站上使用 Django、Python 和 MySQL:创建博客应用程序
- 如何在Django1.6结合Python3.4版本中使用MySql