Installing MySQLdb on Lion

I’ve been meaning to install and use MySQLdb (a Python library that allows one to access MySQL databases) on OS-X Lion, and had to run around for nearly an hour to finally get it working. So heres a small HowTo for those who might also be looking at doing it without wasting all that time.

1. Install the latest version of MySQL from here. Make sure you download the “.dmg” version. Look here for more instructions on how to get this done.

2. Ideally, if the world were perfect, we would have been able to download MySQLdb from here, gone through the regular Python setup process and be done. Unfortunately, life isn’t meant to be that easy, so we will have to do a little work here. First things first, let us add MySQL to our path. To do this append the following line to your ~/.bash_profile file.

Appending MySQL to the Path

Shell

1

2

3

4

5

export PATH=$PATH:/usr/local/mysql/bin

# Aliases for MySQL

aliasmysql=/usr/local/mysql/bin/mysql

aliasmysqladmin=/usr/local/mysql/bin/mysqladmin

aliasmysql_config=/usr/local/mysql/bin/mysql_config

The aliases are not really needed after we’ve added MySQL to the path, but let us just go with this for now.

3. Try this (Replace .xx. which is .18. in the example below, with the version that you have).

Otool on libmysqlclient.dylib

Shell

1

2

3

otool-D`/usr/local/mysql/lib/libmysqlclient.18.dylib`

/usr/local/mysql/lib/libmysqlclient.18.dylib:

libmysqlclient.18.dylib

If you don’t see the path at the end like me (in the example above), this will likely be a problem for you during installation later. Just to be more explicit, you will end up seeing the following error: