14

我是 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>'
4

9 回答 9

15
gem uninstall mysql2

gem install mysql2 --platform=ruby

删除 Rails 特定捆绑目录中的 mysql2 gem 目录并复制粘贴这个新安装的 mysql2 gem

于 2014-01-21T12:51:11.583 回答
6

对于 Rails 3.2.17 和 Ruby 1.9.3-p448 和 mysql2 0.3.11,运行bundle update mysql2更新到 0.3.15 并为我摆脱了错误。

于 2014-04-30T17:35:18.113 回答
1

是的,它发生在带有rails 4.0.0的mysql2 gem的新版本(0.3.13)上。删除供应商目录下的捆绑文件夹,然后重新运行捆绑安装,更新为我解决了这个问题

cd {Your_RailsApp_Root}/vendor/
rm -rf bundle/
cd {Your_RailsApp_Root}
bundle install
bundle update
于 2013-08-19T22:42:58.700 回答
0

你有安装 mysql2 gem 吗?检查您的 gemfile 是否已从您的 rails 应用程序的根目录gem "mysql2"运行。bundle install另外,请确保您在开发环境中下载了 mysql。

于 2013-08-10T05:18:09.697 回答
0

只需降级mysql2版本。就我而言,我使用了“0.2.6”版本,它对我有用。

  gem 'mysql2', '0.2.6'

使用 ruby​​ 版本 2.0.0 和 gem 版本 1.8.25

于 2014-01-22T10:38:10.967 回答
0

bundle exec rake db:migrate我在成功获得bundle install项目宝石后尝试运行时遇到了这个问题,我为此奋斗了一天。

对我来说,mysql2试图加载一个不存在的配置文件。我已经brew install在我的系统上编辑了 mysql,而 mysql2 正在寻找的东西已经存在于 mysql 安装中。我跑了

gem install mysql2 -v 0.5.3 -- --with-mysql-config=/usr/local/Cellar/mysql@5.6/5.6.42/bin/mysql_config --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

将 mysql2 指向正确的配置。

注意你的mysql版本可能不同,你想要的gem版本也可能不同。另请注意:gem 安装路径可能与您的bundle install路径不同。您还可以使用 gem 到您的捆绑目录

gem install --install-dir /path/to/bundle/directory

或者您可以使用捆绑构建配置设置 gem 选项:

bundle config --local build.mysql2 --with-mysql-config="/usr/local/Cellar/mysql@5.6/5.6.42/bin/mysql_config" --with-ldflags=-"L/usr/local/opt/openssl/lib" --with-cppflags=-"I/usr/local/opt/openssl/include"
于 2021-09-29T20:57:31.550 回答
0
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

https://gorails.com/setup/osx/10.14-mojave

于 2019-05-01T21:30:51.120 回答
-1

它对我有用。

  • 宝石卸载mysql2
  • 须藤宝石安装mysql2
于 2019-02-15T11:32:57.207 回答
-5

这解决了我的错误:

[root@localhost cms]# su Harish

[Harish@localhost cms]$ 捆绑安装

[Harish@localhost cms]$ rails s

于 2013-08-23T15:40:14.277 回答