Ruby使用MySQL問題記錄

來源:互聯網
上載者:User

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 <t

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安裝成功。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.