実行環境は以下の通り。
【OS】Mac OS X Server (10.5.6)
【Rails】2.2.2
【Ruby】1.8.6

Rails2.2.2はデフォルトのデータベースがSQLite3に変更になっている。これを従来の通りMySQLで運用する際、以下のスクリプトでデータベースを指定する。


>rails -d mysql [アプリケーション名]


mysqlドライバーが取り除かれているので、gemでインストールする必要がある。

>sudo gem install --remote mysql


ただ、Mac OS Xだとここで以下のエラーが発生する。

>sudo gem install --remote mysql

Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install mysql -- --with-mysql-dir=/usr/local/mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
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.

Provided configuration options:
--with-opt-dir
--without-opt-dir
.
.
.
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.7/gem_make.out


これはMac OSのクライアント版であれば、以下のコマンドで解決。

>sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config


OS Xクライアントであれば、ここまでで解決するのだけど、OS Xサーバーだと上記のスクリプトだとうまいいかない。。。それでいろいろ追っていったところ、サーバー版だとどうやらmysqlのクライアントライブラリが付属していないようなのだ。なのでこれをAppleのDarwin Source Codeからダウンロードしてインストールする。

1. MySQL Client Libraryをダウンロード

>wget http://www.opensource.apple.com/darwinsource/other/MySQL-43.binaries.tar.gz

--2009-01-02 02:03:13-- http://www.opensource.apple.com/darwinsource/other/MySQL-43.binaries.tar.gz
Resolving www.opensource.apple.com... 17.254.17.70
Connecting to www.opensource.apple.com|17.254.17.70|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 95694028 (91M) [application/x-tar]
Saving to: `MySQL-43.binaries.tar.gz'
100%[==========>] 95,694,028 260K/s in 6m 2s

2009-01-02 02:09:16 (258 KB/s) - `MySQL-43.binaries.tar.gz' saved [95694028/95694028]

2. MySQL Client Libraryをインストール

>tar -xzvf MySQL-43.binaries.tar.gz

MySQL-43.binaries/
MySQL-43.binaries/MySQL-43.root.tar.gz
MySQL-43.binaries/README

>cd MySQL-43.binaries
>sudo tar -xzvf MySQL-43.root.tar.gz -C /

3. 改めてgemでmysqlドライバーをインストール (OS Xクライアントとmysql_configのPathが異なっているので、それぞれの環境に合わせてパスを変更する)

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

Building native extensions. This could take a while...
Successfully installed mysql-2.7
1 gem installed


よし、解決。