Ubuntu 8.10下安装Rails的MySQL驱动

February 23rd, 2009 (1,264 views)

要安装MySQL,可以在终端提示符后运行下列命令(它会自动安装mysql-client包),按照提示输入root用户的密码:
$ sudo apt-get install mysql-server

$ mysql --version
mysql  Ver 14.12 Distrib 5.0.67, for debian-linux-gnu (i486) using readline 5.2

在安装好后我就开始了Rails的学习,结果在rake db:create时出现了下面的警告:
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
no such file to load -- mysql

(See full trace by running task with --trace)

大概意思是说从Rails 2.2开始mysql.rb驱动已经被移除了,需要另外安装该gem文件。

$ sudo gem install mysql

结果出现了下面的错误:
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb install mysql
extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
from extconf.rb:1

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out

这是怎么一回事呢?搜索了一把,发现是没有安装ruby1.8-dev的缘故。那么安装就是了。

$ sudo apt-get install ruby1.8-dev
$ sudo gem install mysql

还是有问题,出现以下的错误提示:
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb install 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... no
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... yes
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
--with-opt-include
...
--with-mysqlclientlib
--without-mysqlclientlib

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out

再次搜索一把,发现是需要安装MySQL开发环境libmysql15-dev。

$ sudo apt-get install libmysql15-dev
sudo gem install mysql

现在终于可以开始学习Rails了。

Related Posts

Leave a Reply

Security Code: