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 :
- Download an old copy of mysql 5.0.41
- Download the latest MySQLdb
$ 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”
- Delete the following lines :
- 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!
[...] 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.
gigabuck » Blog Archive » Installing MySQLdb on Leopard with MAMP
13 Feb 09 at 6:23 pm
[...] is required in order to use a socket to connect to the MySQL. See How to install MySQLdb on Leopard with MAMP for more [...]
Owen Mundy » Blog Archive » How to easily set up a campaign finance database (well, kind of) or Make Python work with MAMP via MySQLdb
9 Aug 10 at 2:44 pm
This is out of date… the more recent version of the module is MySQL-python-1.2.3 . The _mysql.c file doesn’t contain ANY instances of uint.
And I think you meant to specify the MAMP version of mysql_config:
mysql_config = /Applications/MAMP/Library/bin/mysql_config
But I still can’t get this to work… the build command returns a bunch of errors, e.g.
_mysql.c:2331: error: ‘_mysql_ConnectionObject’ has no member named ‘open’
_mysql.c:2338: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’
_mysql.c:2345: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’
_mysql.c:2352: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’
_mysql.c:2359: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’
_mysql.c:2422: error: ‘_mysql_ResultObject’ has no member named ‘converter’
_mysql.c:2422: error: initializer element is not constant
_mysql.c:2422: error: (near initialization for ‘_mysql_ResultObject_memberlist[0].offset’)
_mysql.c: In function ‘_mysql_ConnectionObject_getattr’:
_mysql.c:2444: error: ‘_mysql_ConnectionObject’ has no member named ‘open’
lipo: can’t open input file: /var/tmp//ccP1eTos.out (No such file or directory)
error: command ‘gcc-4.2′ failed with exit status 1
Ugh… what a mess.
Fireproofsocks
5 Mar 11 at 4:34 am