10

Currently:

  • SQLAlchemy installed and working (or at least import v0.8.0b2)
  • Mysql (v5.5.16)
  • Distribute (0.6.34)
  • Oracle mysql-python connector
  • Python 3.2
  • Windows 7 32/64 (note that I installed Python 32bits)

The problem is that MySQLdb or Oursql is required and I didn't managed to get any of them working.

Found this but didn't manage to get it working neither.

Edit: If you are aware of an other orm that works with Python3, I'm interested.

martinqt
  • 689
  • 1
  • 7
  • 18
  • [MySQL-python](http://pypi.python.org/pypi/MySQL-python/1.2.4) doesn't seem to support Python 3 for now, but [Oursql](http://packages.python.org/oursql/index.html) seems to support Pyton 3, and I guess you can get [PyMySQL](https://github.com/petehunt/PyMySQL) to work on Python 3.x too. – jadkik94 Jan 05 '13 at 13:25
  • Thanks for your answer. Indeed i saw that oursql should support Python 3 but the installation failed. It told that i'm not using cython. Tried pymysql but don't remember the error. – martinqt Jan 05 '13 at 14:57

4 Answers4

31

I was successful in getting Oracle's MySQL connector for python working with SQLAlchemy on Python 3.3. Your connection string needs to start with "mysql+mysqlconnector://...". After I changed my connection string everything (well, simple things) started working.

The MySQL connector docs can be found here: https://dev.mysql.com/doc/connector-python/en/

The package is up on PyPi: https://pypi.org/project/mysql-connector-python/

Here are the SQLAlchemy docs about using the Python connector: http://docs.sqlalchemy.org/en/latest/dialects/mysql.html#module-sqlalchemy.dialects.mysql.mysqlconnector

Brad Campbell
  • 2,969
  • 2
  • 23
  • 21
  • I'll test this but at the time of the question it didn't worked. Maybe they finally made an update. There wasn't any sqlalchemy for 3.3. – martinqt Mar 20 '13 at 12:13
13

For others who arrive here, this should do it:

  • pip install mysql-connector==2.1.4 # version avoids Protobuf error
  • URI = 'mysql+mysqlconnector://$USER:$PASS@$HOST/$DB'
Fletch F Fletch
  • 411
  • 5
  • 7
2

I tried Oracle's connection, as suggested by @Brad Campbell, but unfortunately it was extremely slow, much slower than the "real" MySQL-Python connection I had been using with SQLAlchemy on Python 2.

After checking SQLAlchemy themselves,

http://docs.sqlalchemy.org/en/latest/dialects/mysql.html#module-sqlalchemy.dialects.mysql.mysqldb

To use MySQL-Python on Python 3, they recommend a fork of it, mysqlclient,

https://github.com/PyMySQL/mysqlclient-python

It is available via pip with pip install mysqlclient, but there are almost certainly other steps you'll need to do to set it up initially. After that though, I was seeing the performance go back to what I was used to, which was about 5x faster than with Oracle's connector.

seaders
  • 3,878
  • 3
  • 40
  • 64
1

I've gotten oursql + SQLAlchemy 0.8.1 + Python 3.3 to work. Building off of LukeCarrier's port, I modified oursql.c to use the correct import levels, and it worked! Try this, and be sure to follow the readme:

https://github.com/clintron/py3k-oursql

You may also need to have the latest version of Cython.

mrgrieves
  • 567
  • 5
  • 19
  • Yes, this works for me, too (using Python 3.2, though). However, I get DBAPIError exceptions when strings contain non-ASCII characters. Is this supposed to be working? – jogojapan Jun 21 '13 at 08:24
  • It should work. I just successfully inserted a Chinese character (北) through this connector. Is your database using UTF-8 or latin1? – mrgrieves Jun 21 '13 at 21:48
  • It's using UTF-8, and I tried `Unicode(100)`, `String(100)` and `String(100, convert_unicode = True)`. But anyway.. I'll continue to experiment. Good to know that it's supposed to be working. Thank you. – jogojapan Jun 22 '13 at 13:37