「gem install mysql2」に失敗したら
rails3でデータベースをMySQLにする場合、次のコマンドになる。
rails new hoge -d mysql
よくよく見ると、「mysql2」というアダプタ経由で接続する前提の模様。
gem install mysql2
これを実行すると下記のエラーが発生。
Building native extensions. This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. /usr/local/bin/ruby extconf.rb checking for rb_thread_blocking_region()... yes checking for mysql_query() in -lmysqlclient... yes checking for mysql.h... no checking for mysql/mysql.h... yes checking for errmsg.h... no ----- errmsg.h is missing. please check your installation of mysql and try again. ----- *** 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 --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/usr/local/bin/ruby --with-mysql-config --without-mysql-config --with-mysql-dir --without-mysql-dir --with-mysql-include --without-mysql-include=${mysql-dir}/include --with-mysql-lib --without-mysql-lib=${mysql-dir}/lib --with-mysqlclientlib --without-mysqlclientlib Gem files will remain installed in /usr/local/lib/ruby/gems/1.9.1/gems/mysql2-0.2.3 for inspection. Results logged to /usr/local/lib/ruby/gems/1.9.1/gems/mysql2-0.2.3/ext/mysql2/gem_make.out
「checking for mysql.h... no」要するに、「mysql.h」が分からないので
コンパイルが出来ないそうです。
インクルードヘッダーがわからないようなので次のコマンドで実行してみる。
gem install mysql2 -- --with-mysql-include=/usr/include/mysql Building native extensions. This could take a while... Successfully installed mysql2-0.2.3 1 gem installed Installing ri documentation for mysql2-0.2.3... Installing RDoc documentation for mysql2-0.2.3...
インストールできたっぽいね!
今回はラピットサイトの[VPS-SB02プラン]で行った結果です。
※ちなみに「VPS-SB02プラン」のrubyのバージョンは確か
1.8.5でありバージョンが古かったです。
下記のバージョンをインストールしてます。
「ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]」