Django连接MySQL数据库
2015-10-31 21:49
761 查看
Django连接数据库本不应该成为一个问题,怎奈我用的是Python 3,不能用那个经典的MySQLdb来解决连接MySQL的问题,因为作者似乎没有继续维护那个库,所以只支持Python 2,不过好在我们用Python 3的还是有其他选择的。
pymysql是一个很好的替代品,本人亲测,Python 3.4 + Django 1.8的环境下完全没有问题。不过要注意一点,除了要用pip3安装pymysql外,还要在Django project的
本来pymysql已经足够了,不过某次翻阅文档时,发现在本地文档的
mysqlclient is a fork of MySQLdb which notably supports Python 3 and can be used as a drop-in replacement for MySQLdb. At the time of this writing, this is the recommended choice for using MySQL with Django。
好吧,既然如此,那下次试试这个吧!
pymysql是一个很好的替代品,本人亲测,Python 3.4 + Django 1.8的环境下完全没有问题。不过要注意一点,除了要用pip3安装pymysql外,还要在Django project的
__ini__.py文件中声明
import pymysql和
pymysql.install_as_MySQLdb()。我一般是在与工程名同名的文件夹下那个
__ini__.py文件中声明的。
本来pymysql已经足够了,不过某次翻阅文档时,发现在本地文档的
django-docs-1.8-en/ref/databases.html#mysql-notes路径下,它告诉我们推荐使用mysqlclient,官方文档的说明是
mysqlclient is a fork of MySQLdb which notably supports Python 3 and can be used as a drop-in replacement for MySQLdb. At the time of this writing, this is the recommended choice for using MySQL with Django。
好吧,既然如此,那下次试试这个吧!
相关文章推荐
- shell 脚本监控MySQL数据库启动状态
- Mysql在实际使用中的部署架构
- ecshop的Mysql操作类
- [Django数据库模型]Django用原始SQL进行Insert/Update操作
- SQLiteOpenHelper类
- 使用 tungsten-replicator4 实现 mysql -- > monogo 数据同步
- LAMP简单架构实验:Apache+NFS+MySQL
- 双机高可用、负载均衡、MySQL(读写分离、主从自动切换)架构设计
- 关于The MySQL server is running with the--skip-grant-tables option so it cannot execute thisstatement
- mysql性能监控指标及分析
- MySQL监控应该知道的九件事
- 【mysql】报错解决方案The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
- [Django数据库模型]Django连接MySQL数据库的简单例子
- PLSQL Developer使用技巧整理
- PLSQL DEVELOPER 使用的一些技巧【转】 .
- SQLiteOpenHelper 使用方法
- mysql在架构中的演变
- 如何使用 PLSQL Developer 远程连接 Oracle 数据库
- django sqlite3迁移到mysql
- PLSQL Developer