There’s a problem with running Ruby on Rails with MySQL on Mac OS X, and the multitude of web pages I found while trying to fix it were not helping. Worse, they made the WEBrick server flat-out crash. Assuming Xcode 2 and MySQL 4.1.15 are installed in their default locations, here’s exactly what I did to finally get running with Rails:

If you’ve already tried installing the mysql gem, remove it:

sudo gem uninstall mysql

If you tried switching your GCC to 3.3, go back to GCC 4.0:

sudo gcc_select 4.0

Run the “fix ruby config” gem:

sudo gem install fixrbconfig

Download the source to the mysql module, unpack it, and change into that directory.

Since the default MySQL install puts itself in /usr/local/mysql, you’ll need to configure and build like this:

export PATH=$PATH:/usr/local/mysql/bin
ruby extconf.rb --with-mysql-config
make

Now you need to give yourself access to the test database before you can run the unit tests:

mysql -u root -p
(type your password here)
grant all on test.* to 'your_user_name_here'@'localhost';
quit;

Then run the tests and install:

ruby test.rb
sudo make install

Now you should be good to go!

UPDATE 1: see also this excellent page that goes through much of the same material. (Wish I had found that sooner.)

UPDATE 2: see also Locomotive, a slick all-in-one Mac Rails package which includes all kinds of stuff precompiled. Unfortunately, this is not useful for running unit/functional tests, so you’ll still need run through the steps here for testing.

UPDATE 2006/01/15: changed the build instructions for the mysql module; for whatever reason, the old one didn’t work this time, so I switched to the –with-mysql-config method and that did the trick.