python使用mysql的三個模塊:mysql.connector、sqlalchemy、MySQLdb


在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/

-= 補充 =-

github上的項目總在更新,有時候需要別的依賴有時候又不需要,有的操作系統上面也默認安裝了一些模塊。如果安裝上碰到什么問題可以留言給我。

要求:Protobuf C++ (version >= 2.6.0) and Python Protobuf (version >= 3.0.0)

 

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文件夾里的文件

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM