Rails gem install mysql throws error: *** extconf.rb failed ***

Whilst reading guides on how to setup a rails dev server under OS X (both Tiger and Leopard), I kept running into issues installing the mysql gem. The guides would instruct you to install the mysql client libraries from the mysql website, which is fine. But to get improved performance under rails, you must install the mysql gem, but in doing so, I would constantly run into issues getting the gem to install correctly. The issues normally arises after running the following command:

sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql

And the resulting error is:

checking for mysql_query() in -lmysqlclient... no

*** extconf.rb failed ***

Could not create Makefile due to some reason, probably lack of

necessary libraries and/or headers.  Check the mkmf.log file for more

details.  You may need configuration options.

Basically, the gem compile fails as a result of not knowing where the correct mysql files are, despite the fact that the command line switch points to the mysql folder.

To fix this problem, use a line like the following:

sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Note that instead of pointing at the mysql folder, we are pointing at a mysql config which is bundled with the mysql client install files.