36

So, looking for a mysql-db-lib that is compatible with py3k/py3.0/py3000, any ideas? Google turned up nothing.

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
thr
  • 19,160
  • 23
  • 93
  • 130

9 Answers9

34

It appears the MySQLdb is pretty much a dead project. However, PyMySQL is a dbapi compliant, pure-python implementation of a mysql client, and it has python 3 support.

EDIT: There's also MySQL Connector/Python. Same idea.

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
itsadok
  • 28,822
  • 30
  • 126
  • 171
  • 1
    Actually, we could not get MySQL Connector/Python to work with Python 3.3 and SQLAlchemy. PyMySQL seems to work great though. – Prof. Falken Sep 30 '13 at 11:43
  • 3
    `pip install mysql-connector-python` works with Python 2.7.11 and 3.5.1. Concerned about [poor performance](http://charlesnagy.info/it/python/python-mysqldb-vs-mysql-connector-query-performance) relative to MySQLdb. – Bob Stein Apr 06 '16 at 15:52
7

I was looking for it too, but also found nothing, so I ported MySQL-python-1.2.3 to py3k you can read it here http://sourceforge.net/p/mysql-python/discussion/70460/thread/61e3a3c9/

twasbrillig
  • 17,084
  • 9
  • 43
  • 67
davispuh
  • 1,419
  • 3
  • 18
  • 30
4

There are currently a few options for using Python 3 with mysql:

https://pypi.python.org/pypi/mysql-connector-python

  • Officially supported by Oracle
  • Pure python
  • A little slow
  • Not compatible with MySQLdb

https://pypi.python.org/pypi/pymysql

  • Pure python
  • Faster than mysql-connector
  • Almost completely compatible with MySQLdb, after calling pymysql.install_as_MySQLdb()

https://pypi.python.org/pypi/cymysql

  • fork of pymysql with optional C speedups

https://pypi.python.org/pypi/mysqlclient

  • Django's recommended library.
  • Friendly fork of the original MySQLdb, hopes to merge back some day
  • The fastest implementation, as it is C based.
  • The most compatible with MySQLdb, as it is a fork
  • Debian and Ubuntu use it to provide both python-mysqldb andpython3-mysqldb packages.

benchmarks here: https://github.com/methane/mysql-driver-benchmarks

Collin Anderson
  • 14,787
  • 6
  • 68
  • 57
2

Here is a working repository for Python 3: https://github.com/davispuh/MySQL-for-Python-3

Zsolti
  • 1,571
  • 1
  • 11
  • 22
2

As for future plans of MySQLdb, you might want to ask the author (Andy Dustman).
His blog is here: http://mysql-python.blogspot.com/

Paul Oyster
  • 1,966
  • 2
  • 12
  • 5
  • 9
    For those finding this post 4.5 years later like me, according to your post, mysql-db support for Python 3 is coming soon, based on that blog. Woohoo. – Nick Mar 16 '13 at 03:07
  • 9
    And for those finding this post 5 years later like me, it looks like that blog hasn't been updated since the above comment, and that Python 3 support for MySQLdb is still non-existent. :( – CptSupermrkt Dec 19 '13 at 14:42
  • 7
    And for those finding this post 7-8 years later like me, there is a official connector for mysql here : http://dev.mysql.com/downloads/connector/python/ ...history is growing up so slowly... – peiman F. Jun 10 '15 at 11:32
  • in 2019, this answer helped me with this: https://stackoverflow.com/a/25724855/4530648 – Attila Toth Feb 24 '19 at 21:21
1

not sure if you're still looking, but you could try this: http://sourceforge.net/projects/mypysql/

1

You can download the mysql-connector-python module compatible with Python3:

http://rpm.pbone.net/index.php3/stat/4/idpl/15667200/dir/rawhide/com/mysql-connector-python3-0.3.2-2.fc16.noarch.rpm.html

Get the "source RPM", unzip it and use it (e.g. put it in your PYTHONPATH, and look at the examples).

Adrian
  • 5,603
  • 8
  • 53
  • 85
0

There is an official Python 2/3 library, downloadable from MySQL website. Oracle released version 1.0.7 to public on 29 September 2012.

It's pure Python and works with MySQL 4.1+

See more details here: http://dev.mysql.com/doc/connector-python/en/connector-python.html

I'm currently using it with MySQL 5.5 and Python 3.2 with no problems thus far :)

Artur Czajka
  • 18,111
  • 2
  • 28
  • 31
0

You're probably better off using Python 2.x at the moment. It's going to be a while before all Python packages are ported to 3.x, and I expect writing a library or application with 3.x at the moment would be quite frustrating.

Benjamin Peterson
  • 19,297
  • 6
  • 32
  • 39