在python中使用mysql其实很简单,只要先安装对应的模块即可,那么对应的模块都有什么?官方也没指定也没提供,pcat就推荐自己遇到的3个模块:mysql.connector、sqlalchemy、MySQLdb
------------------
1. 安装mysql.connector
MySQL Connector/Python is implementing the MySQL Client/Server protocol completely in Python. No MySQL libraries are needed, and no compilation is necessary to run this Python DB API v2.0 compliant driver.
git clone https://github.com/mysql/mysql-connector-python cd mysql-connector-python python setup.py install
官方文档:
http://dev.mysql.com/doc/connector-python/en/
2. 安装sqlalchemy
SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL.
It provides a full suite of well known enterprise-level persistence patterns, designed for efficient and high-performing database access, adapted into a simple and Pythonic domain language.
git clone https://github.com/zzzeek/sqlalchemy cd sqlalchemy python setup.py install
官方文档:
http://www.sqlalchemy.org/docs/
3. 安装MySQLdb
MySQL python client forked from MySQLdb, but support asyncronous query
原官网github:https://github.com/dccmx/mysqldb
但推荐下面的这个改进的
This is the legacy (1.x) version of MySQLdb. While it is still being maintained, there will not be a lot of new feature development.
git clone https://github.com/farcepest/MySQLdb1 cd MySQLdb1 python setup.py install
这个MySQLdb其实不怎么推荐,另外如果要在windows里安装的话,推荐安装已经编译好的exe(不然源码安装的话各种问题):
http://www.codegood.com/downloads
里面MySQL-python-1.2.3.win-amd64-py2.7.exe、MySQL-python-1.2.3.win32-py2.7.exe分别为64位和32位版本
(如果安装MySQLdb后提示:ImportError DLL load failed: %1 不是有效的 Win32 应用程序,那么就安装个64位版本。
如果在64位系统里不能识别到安装在其他盘上的python目录,请参考这文:http://www.cnblogs.com/pcat/p/6021497.html)
官方文档:请看github里doc文件夹里的文件