MySQLdb for Python on Mac OS X Snow Leopard

by Michael

Short step-by-step guide to installing the python MySQL connector. Previously, one had to edit the source files to be able to compile the connector on OS X, this is no longer necessary. Just follow the steps below and hopefully everything works as it should.

Download the package from Sourceforge (currently 1.2.3 is the most recent version):

Extract the tar.gz file. In a terminal, write:
$> tar xzvf MySQL-python-1.2.3.tar.gz

Add the directory containing mysql_config to your path:
$> export PATH=$PATH:{path_to_mysql/bin}

Go to the new directory and run the following commands:

$> sudo python clean
$> sudo python build
$> sudo python install
$> sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
$> sudo ln -s /usr/local/mysql/lib/ /usr/local/mysql/lib/mysql

Check if you can import MySQLdb in python:

$> python
>>> import MySQLdb