Today, I spent more time than planned setting up a Django installation with MySQL database backend. Below are the problems I encountered and the ways how I dealt with them.
mysql_configI'm using what's supposed to be the simplest MySQL installation out there - the official dmg from http://dev.mysql.com/. The installer puts all the files into
/usr/local/mysql(with the regular bin, lib and include directories inside). The installation also includes the usual mysql_config executable which takes care for pointing out all the paths required by the MySQL-python package. The problem is that without the system path preconfigured the MySQL-python installer isn't able to find it. I had to point out to the package where mysql_config is. Luckily, there's a setting for that. I downloaded the package:
(it raised an error but downloaded the files just fine). Then, in a file called site.cfg, I switched the following line
bin/pip install MySQL-python --no-install
#mysql_config = /usr/local/bin/mysql_config
- uncommenting it and putting the right path in place. I was free to continue with the installation:
mysql_config = /usr/local/mysql/bin/mysql_config
bin/pip install build/MySQL-python
The library pathUnfortunately, this didn't solve all the problems, as I kept getting the following error when trying to run any code that used the package:
Error loading MySQLdb module: dlopen(/path/to/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.16.dylib
As it turns out, the Ruby guys have a similar problem with that, and it's in a Rails-related post, where I found a solution. For some mysterious reason, the name of mysqlclient library was saved without the full absolute path, as I could see running the otool command:
$otool -L lib/python2.6/site-packages/_mysql.so lib/python2.6/site-packages/_mysql.so: libmysqlclient.16.dylib (compatibility version 16.0.0, current version 16.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1)
When I changed it to the full path with the install_name_tool command:
sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib lib/python2.6/site-packages/_mysql.so
all worked fine. Hope that helps someone in similar trouble.