Compiling ruby mysql2 native extension against MAMP mysql was always a non-trivial task. It’s solution is well-described in these posts: http://boonedocks.net/mike/… and http://www.beyondcoding.com/….
Unfortunately, the most reecent MAMP version (as of March 2011) has upgraded from MySQL 5.1 to MySQL 5.5. And MySQL, in turn, has switched from GNU Make (with ./configure) to CMake (with cmake .).
Now, the adapted solution goes (assuming Snow Leopard here, minor changes are needed for older versions).
1. Download MAMP sources from http://sourceforge.net/projects/mamp/files/mamp/
2. Mount dmg, copy mysql-5.5.9.tar.gz (the version may change in the future releases) somewhere to your disk (say, Desktop)
$ cd /tmp $ mv /Users/yourname/Desktop/mysql-5.5.9.tar.gz . $ tar xf mysql-5.5.9.tar.gz $ cd mysql-5.5.9 $ sudo port install cmake $ cmake . -DMYSQL_UNIX_ADDR=/Applications/MAMP/tmp/mysql/mysql.sock -DCMAKE_INSTALL_PREFIX=/Applications/MAMP/Library $ make -j 3 $ cp libmysql/*.dylib /Applications/MAMP/Library/lib/ $ mkdir -p /Applications/MAMP/Library/include/mysql $ cp include/* /Applications/MAMP/Library/include/mysql $ sudo env ARCHFLAGS="-arch x86_64" gem install mysql2 -- --with-mysql-config=/Applications/MAMP/Library/bin/mysql_config $ sudo install_name_tool -change /tmp/mysql-5.5.9/libmysql/libmysqlclient.16.dylib /Applications/MAMP/Library/lib/libmysqlclient.16.dylib /opt/local/lib/ruby/gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle $ rm -rf /tmp/mysql-5.5.9 /tmp/mysql-5.5.9.tar.gz
Thanks YJ for the install_name_tool fix!
UPD from Torsten Becker: Please note that the latest version of mysql will not work. You need to use mysql (gem?) version 0.2.11