MAMP and the Ruby MySQL Gem

Update 2011-09-18: See here for the most up-to-date instructions (MAMP 1.9). I got it working on 2.0, but experienced some of the same problems other commenters noted). See also these instructions for MAMP 1.8.

After much frustration, I found a way to get the Ruby mysql Gem installed and talking to my MySQL server on MAMP. Credit goes largely to “Hootbah” who followed a similar path to get MAMP talking to Perl’s MySQL library. Here’s the steps I followed for MAMP 1.7.2:

  1. Install the regular MAMP 1.7.2 dmg package.
  2. Download the MAMP 1.7.2 source code.
  3. Unzip the source code file.
  4. Open the terminal and go into the source code directory.
  5. Untar the mysql file and go into the untarred directory:
    $ tar -xzvf mysql-5.0.41.tar.gz
    $ cd mysql-5.0.41
  6. This is the Hootbah magic…we’re basically compiling libraries here for the Gem to link against.
    $ ./configure –with-unix-socket-path=/Applications/MAMP/tmp/mysql/mysql.sock –without-server –prefix=/Applications/MAMP/Library
    $ make -j2
  7. Copy the compiled libraries into MAMP:
    $ cp libmysql/.libs/*.dylib /Applications/MAMP/Library/lib/mysql
  8. Copy the MySQL headers into MAMP…Hootbah didn’t do this but I had been doing it earlier trying to get around some missing mysql.h problems, and figured I’d keep doing it:
    $ mkdir /Applications/MAMP/Library/include
    $ cp -R include /Applications/MAMP/Library/include/mysql
  9. Install the Ruby MySQL Gem:
    $ sudo env ARCHFLAGS=“-arch i386” gem install mysql – –with-mysql-config=/Applications/MAMP/Library/bin/mysql_config

    After being used to seeing errors spit out by this statement, finally a pleasant surprise:

    Building native extensions. This could take a while…
    Successfully installed mysql-2.7
    1 gem installed

Success!