Python MySQL 模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3644839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 12:03:43  来源:igfitidea点击:

Python MySQL module

pythonmysqlmodule

提问by Alexander

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.

我正在开发一个需要与 MySQL 数据库交互的 Web 应用程序,但我似乎找不到任何适用于 Python 的真正好的模块。

I'm specifically looking for fast module, capable of handling hundreds of thousands of connections (and queries, all within a short period of time of each other), without an significant impact on the speed.

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

采纳答案by Seth

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

MySQLdb几乎是镇上唯一的 python mysql 访问游戏。

回答by detly

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 againstit).

我通常使用SQLObject,但我没有在压力很大的情况下使用它,所以我不能保证性能(话虽如此,我不会反对它)。

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...

回答by Andrew

oursqlis 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.

oursql是 python-mysql 访问的另一个选项。它是一个比 MySQLdb 更完整的 libmysqlclient 包装器。根据我的经验,它往往会更快,并具有许多不错的附加功能。

回答by Yassine ElBadaoui

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

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

There is now the official MysQL Python Connector.

现在有官方的 MySQL Python 连接器。

Install:

安装:

sudo pip install mysql-connector-python

Or download it from here:

或从这里下载:

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

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

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

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