Python 3.3 Mysql 连接器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13846050/
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
Python 3.3 Mysql Connector
提问by user1898723
Possible Duplicate:
MySQL-db lib for Python 3.0?
可能的重复:
Python 3.0 的 MySQL-db 库?
I use python3.3 and can't connect to MySQL, because I don't find module for MySQL connector.
我使用python3.3并且无法连接到MySQL,因为我没有找到用于MySQL连接器的模块。
How do I connect to MySQL with python3.3?
如何使用 python3.3 连接到 MySQL?
采纳答案by Cinder
There is a module called Pymysqlwhich you may like:
有一个名为Pymysql的模块,您可能会喜欢:
"""This pure Python MySQL client provides a DB-API to a MySQL database by talking directly to the server via the binary client/server protocol."""
import pymysql
conn = pymysql.connect(host='127.0.0.1', unix_socket='/tmp/mysql.sock', user='root', passwd=None, db='mysql')
cur = conn.cursor()
cur.execute("SELECT Host,User FROM user")
for response in cur:
print(response)
cur.close()
conn.close()
回答by abarnert
As far as I know, nobody has ported the C extension module for mysqlto Python 3, but there are at least two pure-Python modules that work just fine with Python 3 (and also with PyPy, etc.):
据我所知,没有人将 C 扩展模块移植mysql到 Python 3,但至少有两个纯 Python 模块可以很好地与 Python 3(以及 PyPy 等)配合使用:
A quick google for python3 mysqlturns up a few more (as well as various pointers to these two projects, including previous SO questions that ask exactly the same thing).
对python3 mysql 的快速 google 又出现了一些(以及指向这两个项目的各种指针,包括以前提出完全相同问题的 SO 问题)。

