欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

Ruby使用MySQL问题记录

程序员文章站 2024-01-15 13:26:40
...

使用gem安装mysql2的时候提示以下错误extconf.rb:2:in `require

1.使用gem安装mysql2的时候提示以下错误extconf.rb:2:in `require': no such file to load -- mkmf (LoadError) from extconf.rb:2

Building native extensions. This could take a while...

ERROR: Error installing mysql2:

ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb

extconf.rb:2:in `require': no such file to load -- mkmf (LoadError)

from extconf.rb:2

原因:缺少mkmf,mkmf.rb is part of the ruby1.8-dev package。

解决办法:sudo apt-get install ruby1.8-dev

2.WARNING: This version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1

WARNING: Please use the 0.2.x releases if you plan on using it in Rails

原因:rails版本小于3.1,mysql2版本大于0.3,造成版本不兼容;

解决办法:在Gemfile里面把mysql2的版本调低一点设成gem 'mysql2', '

3.Installing mysql2 (0.3.6) D:/develop/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/defaults/operating_system.rb:9:in `block in

op (required)>': The 'mysql2' native gem requires installed build tools. (Gem::InstallError)

原因:缺少devkit,无法安装mysql2;

解决办法:去'http://rubyinstaller.org/downloads 下载devkit,然后按照 的说明安装测试,再执行即可。

4.安装mysql2时报ERROR:Failed to build gem native extension.,具体如下:

Building native extensions. This could take a while...

ERROR: Error installing mysql2:

ERROR: Failed to build gem native extension.

google后发现很多人在安装的时候把mysql自身的参数带上就可以装成功,,比如带--with-mysql-lib=${mysqlLibPath}或--with-mysql-dir=${mysqlDir}或--with-mysql-config=${mysqlConfigPath}。都有试过还是一样,最后从apt中装了个mysql的开发包libmysqlclient-dev,才从gem上将mysql安装成功。

Ruby使用MySQL问题记录