Setting up Django with MySQL on Mac OS X Lion

January 16, 2012
Software

Surprisingly, this is a lot more annoying that I thought it would be. Some notes to the forgetful future me:

  1. Download the MySQL .dmg installer (64-bit). The registration form can be skipped.
  2. Install MySQL, the MySQLStartupItem, and the MySQL.prefPane in that order (See http://stackoverflow.com/questions/6317614/getting-mysql-work-on-osx-10-7-lion)
  3. Open up the MySQL preference pane and make sure the server is started.
  4. Edit ~/.bash_profile and make sure that the mysql bin directory is in the path (/usr/local/mysql/bin). (The MySQL-python package needs to call mysql_config)
  5. Add a libmysqlclient symlink: sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
  6. pip install MySQL-python

Phew. Don’t forget to update your django SETTINGS file for running locally:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': DATABASE_NAME,
        'USER': USER,
        'PASSWORD': PASSWORD,
        'HOST': 'localhost'
    }
}