Last updated

Install ruby-mysql on Mac OS X 10.4 Tiger

You probably know that the built-in mysql code in Rails sucks. To rephrase that, the ruby-mysql gem contains better code, so you want that. Rails automatically detects if you have ruby-mysql installed or not, and uses it if you have it.

Most notably, you want to install this gem if you get dropped MySQL connections running your Rails application.

So we do:

1$ sudo gem install mysql
2...
3ERROR: Failed to build gem native extension.

Normall this would install fine, but not on Mac OS X. This is because Mac OS X keeps its code, headers and libraries in odd places (compared to Linux). But don’t panic. There’s an easy solution to all this!

Just compile the gem yourself, and add some special ingredients. Well, not even that. Just compile it again like this:

1$ cd /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7
2$ sudo ruby extconf.rb --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include
3$ sudo make
4$ sudo make install

Now, you have the ruby-mysql gem installed and ready to go! No more dropped MySQL connections for Rails!