2010-09-05 95 views
6

我正在開發一個需要與MySQL數據庫接口的Web應用程序,而且我似乎無法找到任何用於Python的優秀模塊。Python MySQL模塊

我特別尋找快速模塊,能夠處理數十萬個連接(和查詢,所有連接都在很短的時間內完成),而不會對速度產生重大影響。

回答

7

MySQLdb幾乎是python mysql訪問的唯一遊戲。

2

我通常使用SQLObject,但我沒有在高度緊張的條件下使用它,所以我不能保證性能(話雖如此,我不會說它)。

從另一個答案複製一些演示代碼:

from sqlobject import * 

# Replace this with the URI for your actual database 
connection = connectionForURI('mysql://server:XXXX') 
sqlhub.processConnection = connection 

# This defines the columns for your database table. See SQLObject docs for how it 
# does its conversions for class attributes <-> database columns (underscores to camel 
# case, generally) 

class Song(SQLObject): 

    name = StringCol() 
    artist = StringCol() 
    album = StringCol() 

# Create fake data for demo - this is not needed for the real thing 
def MakeFakeDB(): 
    Song.createTable() 
    s1 = Song(name="B Song", 
       artist="Artist1", 
       album="Album1") 
    s2 = Song(name="A Song", 
       artist="Artist2", 
       album="Album2") 

def Main(): 
    # This is an iterable, not a list 
    all_songs = Song.select().orderBy(Song.q.name) 

    # Do something by iterating over the song list... 
1

oursql是蟒蛇,MySQL訪問的另一種選擇。它是比MySQLdb更完整的libmysqlclient包裝器。在我的經驗中,我有更多更好的附加功能。