gem ruby mysql_Ruby使用MySQL问题记录

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 <= 3.0.x

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

解决办法:在Gemfile里面把mysql2的版本调低一点设成gem 'mysql2', '< 0.3'就可以了,或者直接gem install mysql2 -v 0.2.7安装一个确切的版本,再在gemfile中将mysql2设成该版本;或者把rails升级到3.1以上版本,该方法未验证。

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,然后按照http://github.com/oneclick/rubyinstaller/wiki/Development-Kit 的说明安装测试,再执行即可。

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安装成功。23f987522c5046c33c7069971df59c81.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值