Jul
11
2008

How to install MySQLdb on Leopard with MAMP

Like many others, I struggled for a good hour to install the recommended MySQL module for Python, which is MySQLdb. So I’m sharing here the solution I found ;-)

The latest MAMP (1.7.1) uses MySQL 5.0.41, and MacOS X Leopard (10.5) uses Python 2.5.1 . As I couldn’t find a prebuilt MySQLdb binary for those versions, well, I had to compile my own.

So let’s go for it :


$ tar zxvf mysql-5.0.41.tar.gz
$ cd mysql-5.0.41
$ ./configure && make
$ sudo make install
$ cd ..

(now MySQL is installed in /usr/local/)

$ tar zxvf MySQLdb...
$ cd MySQLdb...

  • In the MySQLdb folder, edit the file _mysql.c
    • Delete the following lines :

      #ifndef uint
      #define uint unsigned int
      #endif

    • Replace 2 occurences of “uint” by “unsigned int”
  • Then edit the site.cfg file, and set the mysql_config variable to “/usr/local/bin/mysql_config”


(Still in the MySQLdb folder)

$ python setup.py clean
$ python setup.py build
$ sudo python setup.py install
$ sudo rm /tmp/mysql.sock
$ sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

And that’s it! You should now be able to “import MySQLdb” in python. Good luck!

Share on:
  • Facebook
  • Twitter
  • Google Bookmarks
  • Digg
  • del.icio.us
  • StumbleUpon
  • Technorati
Written by sylvain in: Tech stuff |

1 Comment »

  • [...] of getting MySQLdb to compile with MAMP so I can get Python talking to MySQL, I ran across Sylvain Zimmer’s post and follow his [...]

    [WORDPRESS HASHCASH] The comment’s server IP (64.57.64.90) doesn’t match the comment’s URL host IP (64.57.71.218) and so is spam.

    Pingback | February 13, 2009

RSS feed for comments on this post. TrackBack URL

Leave a comment

Theme: TheBuckmaker.com Website Design | Postident, Domainregistration

This work by Sylvain Zimmer is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported.