Installing python-mysql connector MySQLdb after Snow Leopard upgrade

After upgrading to Snow Leopard and all its 64-bit goodness, I discovered that the upgrade to python 2.6.1 64-bit understandably broke my python-mysql connector which was previously compiled against my 32-bit installation of XAMPP with MySQL. I tried several different paths to make the new python play nice with the existing XAMPP installation. Here's the one that worked:
  1. Insure that you have the MySQL include directory needed for compilation against the XAMPP MySQL binary you are running. I'm running a 5.0.x build of MySQL and to get the proper include dir I simply downloaded the 32-bit DMG for Mac from here. After installation, I simply copied the include dir to my xampp installation.
    cp -R /usr/local/mysql/include /Applications/xampp/xamppfiles/
    Now the xampp version of mysql_config will point to your newly installed include dir, so you are ready to compile against it.
  2. If you don't already have it, grab the python-mysql connector source. I'm using MySQL-python-1.2.3c1
  3. Tell your 64-bit python to always run in 32-bit mode
    defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
  4. cd into the MySQL-python source directory and build it for 32-bit mode
    ARCHFLAGS='-arch i386' python setup.py build
  5. install it
    ARCHFLAGS='-arch i386' python setup.py install
  6. exit the source directory "cd ~" and test your new install
    pythonPython 2.6.1 (r261:67515, Jul  7 2009, 23:51:51)[GCC 4.2.1 (Apple Inc. build 5646)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb
    You're welcome.
Share Comments