Wednesday, 1 May 2013

Python MySQL on Mac OSX

This is how to setup MySQLDB to work with mysql on Mac OSX Mountain lion. This should also work with other unix type systems and linux provided you change to the paths to where mysql is installed on your system.

1) Add mysql bin files to path (so mysql_config can be found)
export PATH=/usr/local/mysql/bin/:$PATH
2) Create env var to shared library (so libmysqlclient.18.dylib can be found)
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
3) Install the python module using pip
pip install mysql-python

to make these changes permanent add them to ~/.profile

If you are using virtualenv in python you may also need to add the DYLD_LIBRARY_PATH to in the activate script found under the bin folder of the virtual env.

No comments:

Post a Comment