代码之家  ›  专栏  ›  技术社区  ›  Alexander

Python-MySQL模块

  •  6
  • Alexander  · 技术社区  · 15 年前

    我特别寻找快速模块,能够处理数以万计的连接(和查询,在短时间内彼此),而不会对速度产生重大影响。

    4 回复  |  直到 15 年前
        1
  •  7
  •   Seth    15 年前

    MySQLdb 几乎是城里唯一一款可以访问python-mysql的游戏。

        2
  •  10
  •   Yassine ElBadaoui    13 年前

    我想我的答案将是对游戏领域的更新。

    现在有了官方的MysQL-Python连接器。

    sudo pip install mysql-connector-python
    

    或者从这里下载:

    http://dev.mysql.com/downloads/connector/python/

    http://dev.mysql.com/doc/refman/5.5/en/connector-python.html

        3
  •  2
  •   detly    15 年前

    我通常使用 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...
    
        4
  •  1
  •   Andrew    15 年前

    oursql 是python-mysql访问的另一个选项。它是libmysqlclient的一个比MySQLdb更完整的包装器。在我的经验中,它有很多很好的附加功能。