MySQL v5.5 is GA, but is it working with Python? Yes, it does. Below you’ll find some quick, small tests I did with MySQLdb, oursql and our own MySQL Connector/Python.
My desktop is a Mac, but when it works on that, I’m sure it works elsewhere too. If not, just let us know!
MySQL for Python (aka MySQLdb)
Installing MySQL v5.5.8 64-bit from tar ball on MacOS X 10.6, it compiled fine and the module loaded giving me the expected result:
>>> import MySQLdb
>>> cnx = MySQLdb.connect(user='root')
>>> cur = cnx.cursor()
>>> cur.execute("SELECT VERSION()")
1L
>>> print cur.fetchall()
(('5.5.8',),)
oursql
oursql is an alternative for MySQLdb. Both are using the MySQL C API and thus need to be compiled from source (if you don’t find binaries of course).
>>> import oursql
>>> cnx = oursql.connect(user='root')
>>> cur = cnx.cursor()
>>> cur.execute("SELECT VERSION()")
>>> print cur.fetchall()
[(u'5.5.8',)]
MySQL Connector/Python
Our own MySQL Connector/Python doesn’t need compiling and doesn’t need any MySQL software installed to be able to connect to a MySQL server. Current unittests run fine against MySQL v5.5.8.
>>> cnx = mysql.connector.connect(user='root')
>>> cur = cnx.cursor()
>>> cur.execute("SELECT VERSION()")
-1
>>> print cur.fetchall()
[(u'5.5.8',)]
Conclusion
One can’t really conclude anything with the simple tests above, but it looks like MySQL v5.5 will work fine with Python.
Comments
Hi Geert,
Python -> 2.4.3 (#1, Jan 14 2011, 22:42:01) mysql -> Ver 14.14 Distrib 5.5.8, for Linux (x86_64) MySQLdb.version_info -> (1, 2, 1, ‘final’, 1)
Doing the above tests: >> cur = cnx.cursor() Traceback (most recent call last): File “”, line 1, in ? File “/usr/lib64/python2.4/site-packages/MySQLdb/connections.py”, line 219, in cursor return (cursorclass or self.cursorclass)(self) AttributeError: ‘Connection’ object has no attribute ‘cursorclass’ >>> ---->
Tried upgrading MySQLdb-Python to 1.2.3 but there are multiple mysql related errors.
build/lib.linux-x86_64-2.4/MySQLdb running build_ext building ‘_mysql’ extension gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fPIC -Dversion_info=(1,2,3,‘final’,0) -Dversion=1.2.3 -I/usr/include/mysql -I/usr/include/python2.4 -c _mysql.c -o build/temp.linux-x86_64-2.4/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -fPIC -g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing In file included from _mysql.c:29: pymemcompat.h:10:20: error: Python.h: No such file or directory _mysql.c:30:26: error: structmember.h: No such file or directory _mysql.c:62: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘*’ token
--->
I am working on it now, but if you have some tips, please let me know.
Thanks, Alex.
Solved the issue using the “magic” bellow:
yum install python-devel.x86_64
when installing MySQLdb-Python it was complaining about missing libmysqlclient_r.so.15, I only had version 16, downgrade not an option. Created a sym link to libmysqlclient_r.so.16 so that the install went smooth, nevertheless MySQLdb-Python was failing with the errors in previous post.
Installed python-devel, now it is ok.
Maybe this will help somebody.
Cheers, Alex.