18

Possible Duplicate:
MySQL-db lib for Python 3.0?

I use python3.3 and can't connect to MySQL, because I don't find module for MySQL connector.

How do I connect to MySQL with python3.3?

Community
  • 1
  • 1
user1898723
  • 251
  • 1
  • 3
  • 5
  • 1
    This is a duplicate of http://stackoverflow.com/questions/4960048/python-3-and-mysql and/or http://stackoverflow.com/questions/384471/mysql-db-lib-for-python-3-0. – abarnert Dec 12 '12 at 18:21
  • 5
    Actually not duplicate: I searched long and hard for a connector for python3.2. Unfortunately that connector doesn't work with 3.3 – Sheena Apr 01 '13 at 10:05

2 Answers2

19

There is a module called Pymysql which you may like:

"""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()
Cinder
  • 1,599
  • 2
  • 13
  • 23
9

As far as I know, nobody has ported the C extension module for mysql to Python 3, but there are at least two pure-Python modules that work just fine with Python 3 (and also with PyPy, etc.):

A quick google for python3 mysql turns up a few more (as well as various pointers to these two projects, including previous SO questions that ask exactly the same thing).

General Grievance
  • 4,555
  • 31
  • 31
  • 45
abarnert
  • 354,177
  • 51
  • 601
  • 671