MySQLdb for Python 2.5

James Stroud jstroud at mbi.ucla.edu
Sat Sep 30 06:08:08 EDT 2006


Harold Trammel wrote:
> Hi everyone,
> 
> Does anyone know the status of a version of MySQLdb that will work with 
> Python 2.5?  I will accept a workaround if you know one.  Thanks in 
> advance.
> 
> Harold Trammel

I could not find a way around this requirement, but you will want to 
manually add libz to your building with this version. This seems to be 
how to do this when you run setup.py:

      python setup.py -lz [other args] install

This is for mysqldb "MySQL-python-1.2.1_p2" (which I believe is the 
latest).

I built this a few days ago and finally tested today and got this 
terribly annoying (and apparently well documented) error:

[stacktrace clipped]
LookupError: unknown encoding: latin1_swedish_ci

My setup: python 2.5, very old mysql servers (C. 2003?), mysqldb 
1.2.1_p2. It seems the problem is related to mysqldb, but I'm not sure.

I found the only real work-around here:

   http://mail.python.org/pipermail/python-list/2006-July/350408.html

Its ugliness manifests in my code as such:


#######################################################################
# workaround function for problems with encoding
#######################################################################
def _csn(*args, **kwargs): return 'utf-8'

#######################################################################
# init_mysql()
#######################################################################
def init_mysql(the_db="some_db"):
   adb = MySQLdb.connect(
            host="sql.some.institute.edu",
            # charset="utf8", # <-- our mysql servers too old for this
            user="my_login",
            passwd="pa55w0rd",
            db=the_db
   )
   adb.character_set_name = instancemethod(_csn, adb, adb.__class__)
   return adb


This fix passes some initial rudimentary tests. No guarantees on proper
handling of unicode. If you are using unicode, you may want to test it 
thoroughly with this fix and report your results (preferably on this 
comp.lang.python).


James




More information about the Python-list mailing list