MySQLdb Installation

How do I install MySQLdb?#

Download from sourceforge and extract.

Build#

$ python setup.py clean
$ python setup.py build
$ sudo python setup.py install

Mac OS X#

You may have to edit setup_posix.py and change the line below (before building):
mysql_config.path = "mysql_config"

to

mysql_config.path = "/usr/local/mysql/bin/mysql_config"

Note: you have to specify the path to your mysql_config unless you have installed mysql.com package for Mac.

Errors#

If you get this compile error#

/usr/include/sys/types.h:92: error: duplicate ‘unsigned’  
/usr/include/sys/types.h:92: error: two or more data types in declaration specifiers  

edit the _mysql.c file and comment out this line

#define uint unsigned int

Bitness#

Make sure if you python is 32 bit, that your MySQL is 32 bit also.

Using virtualenv#

If you are installing MySQLdb in a virtualenv instance, it may be compiling against the system python, which may be 64-bit. Read up on Installing Python Packages.

Sources#

brainfault.com, etc


Python - Linux - MySQL