Wednesday, February 20, 2008

MySQL for Python (MySQLdb)

Quick note about building the MySQL-Python module under OS X 10.5 w/ MySQL 5.0.51a:
When building there are some issues w/ the default setup so you need to change some files. The Red Elephants blog describes one approach, this way is more "proper" and makes less changes:

Step 1
install MySQL
Step 2
extract MySQL-python-1.2.2.tar.gz
Step 3
modify the file "site.cfg" uncomment the line starting with "#mysql_config" (line #13):
mysql_config = /usr/local/mysql/bin/mysql_config

Step 4
if you get errors about "error: duplicate ‘unsigned’" during compiling change the file _mysql.c at line 38 from:
#define uint unsigned int

to:
#include <sys/types.h>


Step 5
python setup.py build
sudo python setup.py install

A side note: defining uint explicitly like that isn't really best "practices" and causes problems. The mysql client library header will include sys/types.h anyway so we just include it a little bit earlier.