Although I don’t write much of code these days, I do architect and RnD on the new frameworks and modules that get adopted in my projects. This implies that I need to have a development environment ready for trying out new frameworks to adopt. When I had to reinstall my Mac because of performance issues I had to setup my environment again and it turned out to be a pain to install the MySQLdb connector for Python on Mac OSX. So here are the steps

1. Download XCode – You will need this for compiling the python MySQLdb Source
2. Download 64-BIT version of MYSQL Community
3. Download MySQL-python-1.2.3.tar.gz from here
4. bash_profile – Add the following in your .bash_profile located in your ~ directory
alias mysql=/usr/local/mysql/bin/mysql
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
5. gcc-4.0 – When you try to build MySQLdb it will look for gcc-4.0 so create a soft link for your gcc
sudo ln -s /usr/bin/gcc-4.0 /usr/bin/gcc
6. ARCHFLAGS This is where you need to be careful. You will need to set this flag based on your architecture, otherwise importing MySQLdb will throw an “Architecture does not match” error after building
export ARCHFLAGS='-arch i386'
or
export ARCHFLAGS='-arch x86_64'
7. site.cfg – update this file to point to you mysql config file
mysql_config = /usr/local/mysql/bin/mysql_config
8. First clean the MySQLdb installation if you already have one
sudo python setup.py clean
9. sudo python setup.py build
10. sudo python setup.py install
11. Now test by importing mysqldb in your python shell
>>import MySQLdb

Follow on Google+ LinkedIn Updated on March 11, 2013 at
Post your comment

All the fields must be filled out before posting.