Skip to content

Avian Bone Syndrome

An exercise in futility by Daniele Nicolucci

Menu
  • About ABS
Menu

Installing the MySQLdb Python module on Snow Leopard

Posted on 2010-04-042010-07-14 by Daniele Nicolucci

Needing to access a MySQL database through Python, I was faced by the inability to easily install the MySQLdb module. I do use MacPorts, but after running the obvious
sudo port install py26-mysql
I realized that I would be downloading, compiling and installing a new instance of Python, a new instance of MySQL (I prefer the simplicity of MAMP), and who knows what else.

Installing the module alone doesn’t work, because MAMP installs no headers; and copying the headers from the vanilla MySQL distribution doesn’t help either, because a few of the required files are generated on the fly during the installation of MySQL itself.

The solution, it turns out, is relatively simple. Follow along.

Step 1: download the latest MySQL Community Server in DMG format for x86-64 from this page, and install the main package. Worry not: nothing is going to be started on boot, so this is not going to mess with your pre-existing MySQL installation. The package is going to be installed in /usr/local/mysql-5.1.45-osx10.6-x86_64/, with a handy /usr/local/mysql/ symbolic link.

Step 2: download the latest MySQLdb Python module from this page, and unpack it somewhere.

Step 3: set the $PATH environment variable to include /usr/local/mysql. That’s because the module’s setup.py is going to need to call mysql_config, and you want it to find the one you just installed, as it comes with all the stuff it needs.

Step 4: do the classic build and install dance, making sure you prepend the commands with ARCHFLAGS=’-arch x86_64′. This is because you want to compile a 64-bit module.

In short:
tar vxfz MySQL-python-1.2.3c1.tar.gz
cd MySQL-python-1.2.3c1
export PATH=/usr/local/mysql:$PATH
ARCHFLAGS='-arch x86_64' python setup.py build
ARCHFLAGS='-arch x86_64' python setup.py install

If all went fine, you should be able to do this without getting any errors:
octavarium:~ jollino$ python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> print MySQLdb
<module 'MySQLdb' from '/Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg/MySQLdb/__init__.pyc'>

Enjoy!

Post navigation

← iPad, iTunes, iPhone OS; or: how you are not forced to use them
Batch-converting images for an HDTV →

3 thoughts on “Installing the MySQLdb Python module on Snow Leopard”

  1. Jon Z says:
    2010-08-12 at 17:50

    Works Great BUT I needed to set the PATH as:
    export PATH=/usr/local/mysql/bin:$PATH

  2. Pingback: Setting up Django with MAMP on Mac OS X Lion (in ? steps) | Thomas M. Alisi
  3. Adnan says:
    2012-09-15 at 19:04

    You could do same by setting the path of MySQL installed by MAMP? No?

Comments are closed.

Written by a human

All text in this blog was written the old-fashioned way, without going through an AI / LLM. Any typos, mistakes and inconsistencies are proudly mine.

If you like this…

Did you enjoy reading this post without ads? If so, you may consider supporting this blog via Ko-fi!

Where was that?

Time travel

  • June 2026 (1)
  • May 2026 (1)
  • April 2026 (1)
  • November 2022 (1)
  • March 2022 (1)
  • December 2021 (1)
  • October 2020 (1)
  • August 2020 (1)
  • May 2020 (1)
  • March 2020 (3)
  • February 2020 (1)
  • April 2019 (1)
  • March 2016 (1)
  • July 2015 (1)
  • May 2015 (3)
  • April 2015 (2)
  • November 2014 (1)
  • August 2014 (2)
  • September 2013 (2)
  • April 2013 (1)
  • March 2013 (1)
  • October 2012 (1)
  • June 2012 (1)
  • March 2012 (1)
  • December 2011 (1)
  • November 2011 (3)
  • October 2011 (2)
  • July 2011 (1)
  • April 2011 (1)
  • January 2011 (1)
  • December 2010 (2)
  • November 2010 (1)
  • October 2010 (3)
  • September 2010 (16)
  • August 2010 (12)
  • July 2010 (10)
  • June 2010 (1)
  • May 2010 (7)
  • April 2010 (3)

Categories

  • Business (2)
  • Culture (13)
  • Electronics (4)
  • Huh? (1)
  • iOS (4)
  • Linguistics (11)
  • Music (8)
  • Personal (5)
  • Photography (10)
  • Podcast (5)
  • Science (7)
  • Society (28)
  • Technology (50)
  • Travel (2)
  • Tutorials (13)
  • TV (7)
  • Video games (6)

Tags

1984 (3) absp (3) apple (11) bluray (3) camera (4) communication (3) coronavirus (5) covid19 (5) culture (4) death (3) dream theater (4) ebooks (5) english (4) facebook (3) ios (8) ipad (4) iphone (10) iphone os (4) italian (3) italy (6) james labrie (3) jordan rudess (3) language (6) languages (3) linguistics (6) lockdown (5) mac (6) memories (3) mike portnoy (3) opus (4) orwell (3) os x (6) personal (4) photography (10) podcast (6) projects (3) rant (4) reading (4) spanish (3) the big bang theory (3) tutorial (12) tv (5) twitter (3) video games (6) work (3)
© 2026 Avian Bone Syndrome | Powered by Minimalist Blog WordPress Theme
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
SettingsAccept
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT