Nick Sellen

MAMP with MySQL ruby gem

25 Jun 2011

The problem

Installing mysql2 (0.2.6) with native extensions /Users/nick/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/installer.rb:533:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

        /Users/nick/.rvm/rubies/ruby-1.8.7-p334/bin/ruby extconf.rb 
checking for rb_thread_blocking_region()... no
checking for mysql.h... no
checking for mysql/mysql.h... no
-----
mysql.h is missing.  please check your installation of mysql and try again.
-----

Ok, so we need the headers

Fortunately you can download MAMP source form their website - this gives you a .dmg with lots of .tar.gz files, you just need the mysql one.

I tried just copying the include directory as it was - but loads of the header files have variables that need replacing.

Let's compile this thing

compilation uses cmake, so ensure you have that first.

tar zxvf mysql-5.5.9.tar.gz
cd mysql-5.5.9
cmake .
make
mkdir /Applications/MAMP/include/
cp -r include/* /Applications/MAMP/include/
cp libmysql/*.dylib /Applications/MAMP/Library/lib

yay!

Installing mysql2 (0.2.6) with native extensions  
Your bundle is complete!