Prasenjit Kumar Nag a.k.a Joy

A Developers Adventure in Coding

Using MAMP’s Mysql Installation With Rails App

Being primarily a PHP developer I always have one AMP package installed in my machine no matter what platform I work with. Now-a-days as I work on my macbook I have MAMP installed.

Few days back I was trying to install mysql2 gem to use in Rails app which acts as the interface between MySql engine and Rails(or Ruby) apps. But it was constantly failing every time I tried to. I even tried to install previous versions of mysql2 gem but no luck. Then I tried to have a closer look at the error the bundle install command was spitting out into the terminal.

It was not being able to find mysql header files which are required to compile mysql2 gem. After searching in the internet I found out MAMP doesn’t ship mysql headers by default.

So The options I had was either recompile Mysql from source and add headers into proper MAMP Directory. Or manage another mysql installation only for rails which is a whole lot of pain. So I had to go for one, I searched through Stack Overflow and found some tutorials on how to do that. After studying some of those I finally took a backup of mamp and started the recompilation process. Here are the steps I followed:

Take a backup of your whole MAMP directory if by any chance you mess it up. :) It’s always safe.

  1. First you need to download the MAMP open source components from their source forge page here download the components for mamp 2.0.2 that is the latest now.

  1. Recently MAMP have switched from MySql 5.1 to to MySQL 5.5. And MySQL, in turn, has switched from GNU Make (with ./configure) to CMake (with cmake .). So you need to have cmake installed in you Mac. You can do that easily using brew or macport using the following command
brew install cmake


port install cmake
  1. Suppose You have downloaded it into your desktop then Extract and put the mysql-5.5.9.tar.gz file into your desktop and type in the following command in your terminal.
$ 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
 $ 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
  1. after this you should see 1 Gem installed successfully message into the termnal and you gem has been install successfully. Now you need to symlink a bundle from your mysql Library into /user/lib. Run the following command in the terminal.
sudo ln -s /Applications/MAMP/Library/lib/libmysqlclient.16.dylib /usr/lib/libmysqlclient.16.dylib [/bash]
<div>5. Now clean up your temp directory</div>


rm -rf /tmp/mysql-5.5.9 /tmp/mysql-5.5.9.tar.gz


and you are done. Now you can try bundle install or  rake db:create
and they should work fine. :)
Happy reusing MAMP’s mysql with your rails applications :)