Ruby-on-rails rails 无法加载此类文件 -- mysql2/mysql2 (LoadError)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18158775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
rails cannot load such file -- mysql2/mysql2 (LoadError)
提问by Harish Gopalakrishnan
I am newbie to ruby on rails i could not find the solution for this error:
我是 ruby on rails 的新手我找不到此错误的解决方案:
rails s
/usr/local/share/gems/gems/mysql2-0.3.13/lib/mysql2.rb:8:in `require': cannot load such file -- mysql2/mysql2 (LoadError)
from /usr/local/share/gems/gems/mysql2-0.3.13/lib/mysql2.rb:8:in `<top (required)>'
from /usr/local/share/gems/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
from /usr/local/share/gems/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /usr/local/share/gems/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
from /usr/local/share/gems/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
from /usr/local/share/gems/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
from /usr/local/share/gems/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
from /usr/local/share/gems/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
from /home/Harish/Documents/simple_cms/config/application.rb:7:in `<top (required)>'
from /usr/local/share/gems/gems/railties-4.0.0/lib/rails/commands.rb:76:in `require'
from /usr/local/share/gems/gems/railties-4.0.0/lib/rails/commands.rb:76:in `block in <top (required)>'
from /usr/local/share/gems/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap'
from /usr/local/share/gems/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
回答by Neeraj Kumar
gem uninstall mysql2
gem install mysql2 --platform=ruby
delete the mysql2 gem directory in your rails specific bundle directory and copy paste this newly install mysql2 gem
删除 Rails 特定包目录中的 mysql2 gem 目录,然后复制粘贴这个新安装的 mysql2 gem
回答by Eric
For Rails 3.2.17 and Ruby 1.9.3-p448 and mysql2 0.3.11, running bundle update mysql2updated to 0.3.15 and got rid of the error for me.
对于 Rails 3.2.17 和 Ruby 1.9.3-p448 和 mysql2 0.3.11,运行bundle update mysql2更新到 0.3.15 并为我摆脱了错误。
回答by Shan Valleru
Ya, It's happening with new version(0.3.13) of mysql2 gem with rails 4.0.0. Deleting the bundle folder under vendor directory, and rerunning bundle install, update fixed this issue for me
是的,它发生在带有 rails 4.0.0 的 mysql2 gem 的新版本(0.3.13)上。删除 vendor 目录下的 bundle 文件夹,然后重新运行 bundle install,更新为我解决了这个问题
cd {Your_RailsApp_Root}/vendor/
rm -rf bundle/
cd {Your_RailsApp_Root}
bundle install
bundle update
回答by Matt McNaughton
Do you have the mysql2 gem installed? Check that your gemfile has gem "mysql2"and then run bundle installfrom the root of your rails app. Also, ensure that you mysql downloaded in your development environment.
你有安装 mysql2 gem 吗?检查您的 gemfile 是否具有gem "mysql2",然后bundle install从 Rails 应用程序的根目录运行。另外,请确保您在开发环境中下载了 mysql。
回答by Neeraj Kumar
just downgrade the mysql2 version. In my case, I used '0.2.6' version and it worked for me.
只需降级mysql2版本即可。就我而言,我使用了“0.2.6”版本,它对我有用。
gem 'mysql2', '0.2.6'
with ruby version 2.0.0 and gem version 1.8.25
使用 ruby 版本 2.0.0 和 gem 版本 1.8.25
回答by Duke
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
from
https://gorails.com/setup/osx/10.14-mojave
从
https://gorails.com/setup/osx/10.14-mojave
回答by Hoang Tam Le
It work for me.
它对我有用。
- gem uninstall mysql2
- sudo gem install mysql2
- bundle
- gem卸载mysql2
- 须藤宝石安装mysql2
- 捆
回答by Harish Gopalakrishnan
this solved my error:
这解决了我的错误:
[root@localhost cms]# su Harish
[root@localhost cms]# su Harish
[Harish@localhost cms]$ bundle install
[Harish@localhost cms]$ 捆绑安装
[Harish@localhost cms]$ rails s
[Harish@localhost cms]$ rails s

