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):
http://sourceforge.net/projects/mysql-python/files/mysql-python/

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 setup.py clean
$> sudo python setup.py build
$> sudo python setup.py 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
Advertisements