Python MySQL module

后端 未结 4 1647
逝去的感伤
逝去的感伤 2021-02-06 09:19

I\'m developing a web application that needs to interface with a MySQL database, and I can\'t seem to find any really good modules out there for Python.

I\'m specificall

相关标签:
4条回答
  • 2021-02-06 09:56

    oursql is another option for python-mysql access. It is a much more complete wrapper of libmysqlclient than MySQLdb. Tends to be faster in my experience with lots of nice additional features.

    0 讨论(0)
  • 2021-02-06 10:01

    I usually use SQLObject, but I haven't used it under highly stressful conditions, so I couldn't vouch for performance (having said that, I wouldn't speak against it).

    To copy some demo code from another answer:

    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...
    
    0 讨论(0)
  • 2021-02-06 10:11

    MySQLdb is pretty much the only game in town for python mysql access.

    0 讨论(0)
  • 2021-02-06 10:18

    I think my answer will be an update to the game field.

    There is now the official MysQL Python Connector.

    Install:

    sudo pip install mysql-connector-python
    

    Or download it from here:

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

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

    0 讨论(0)
提交回复
热议问题