To connect to a MySQL database from Django or a python script you have to install MySQLdb. The installation of the package on MacOSX is not straightforward, so here is a small howto.

  • Download and unpack the MySQLdb package
  • Edit the setup-posix.py file, and change the line below:
    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

  • Build
     python setu.py clean
     python setup.py build
     sudo python setup.py install
    

    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 this line

    #define uint unsigned int