Compiling the MySQL2 gem on OS X with any version of MAMP

There are a number of solutions for compiling mysql with MAMP on OS X but there’s a simpler solution.

  1. Download and install MySQL (any version, I did 5.5.14 which is the latest as of this writing). Choose the “Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive” option.
  2. From Terminal, run the following in your rails app’s directory:

    sudo gem install mysql2 --version=0.2.6 -- --with-mysql-dir=/usr/local/mysql
    GEMDIR=`dirname \`bundle show rails\``
    sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ${GEMDIR}/mysql2-0.2.6/lib/mysql2/mysql2.bundle
  3. In your database.yml file point to MAMP’s mysql.sock file:

    socket: /Applications/MAMP/tmp/mysql/mysql.sock
  • Remco Rakers

    Hi Paul! Thanks for the provided solution. I had to tweak it a little bit (other ruby version etc.) to get my MAMP MySQL version working together with Rails, but your solution was helpful!

  • Manuel Fittko

    I just found out that installing mysql via (home)brew and using MAMP’s my-large.cnf file as global mysql config file by placing it in /etc/ as my.cnf does the job, too…

    1. brew install mysql
    2. sudo cp /Applications/MAMP/Library/support-files/my-large.cnf  /etc/my.cnf
    3. sudo gem install mysql2 –version=0.2.7 — –with-mysql-dir=/usr/local/mysql
    ( I also specified the socket in the database.yml like Paul did)

    And don’t ask me why you should install both MAMP and standard mysql, it was the only way to go for me, since nothing else worked.

  • Manuel Fittko, your way worked for me. Thanks.