MySQL mysql2 和 rails3 的运行时错误(捆绑程序)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3467054/
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
RuntimeError with mysql2 and rails3 (bundler)
提问by Swistak
I get this error
我收到这个错误
`establish_connection': Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (no such file to load -- active_record/connection_adapters/mysql2_adapter) (RuntimeError)
from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-
Hereis dump of whole error and my config and gemfile.
这是整个错误的转储以及我的配置和 gemfile。
采纳答案by Josh W Lewis
I had the same error after upgrading from Ubuntu 11.10 to 12.04. This is how I fixed the problem:
从 Ubuntu 11.10 升级到 12.04 后,我遇到了同样的错误。这是我解决问题的方法:
gem uninstall mysql2
bundle
I think the key here is the 'native extensions' -- I suppose when I installed last, I was using a different version of mysql.
我认为这里的关键是“本机扩展”——我想当我上次安装时,我使用的是不同版本的 mysql。
Installing mysql2 (0.3.11) with native extensions
回答by stream7
I was getting the same error while using rails 3.0.7 and mysql2 0.3.2. The solution, which I found here, is to use an older version of mysql2. Thus edit your gemfile to
我在使用 rails 3.0.7 和 mysql2 0.3.2 时遇到了同样的错误。我在这里找到的解决方案是使用旧版本的 mysql2。因此将您的 gemfile 编辑为
gem 'mysql2', '< 0.3'
and run
并运行
bundle install
回答by vrybas
Also need to change adapter from mysql
to mysql2
in database.yml as said here
Install mysql2 gem on Snow Leopard for Rails 3 with rvm
还需要更改适配器从mysql
到mysql2
在database.yml中作为这里说
用RVM安装mysql2在Snow Leopard上的宝石为Rails 3
From:
从:
development:
adapter: mysql
development:
adapter: mysql
To:
到:
development:
adapter: mysql2
development:
adapter: mysql2
回答by amaseuk
Did you include the mysql2 gem in your gemfile instead of the old mysql gem, and ran bundle install afterwards?
您是否在您的 gemfile 中包含了 mysql2 gem 而不是旧的 mysql gem,然后运行了 bundle install?
回答by mmell
If you're using rvm, and possibly added mysql2 outside of rvm, try these steps: Confirm that your Gemfile says:
如果您使用的是 rvm,并且可能在 rvm 之外添加了 mysql2,请尝试以下步骤: 确认您的 Gemfile 显示:
gem 'mysql2'
or for Rails2.x:
或 Rails2.x:
gem 'mysql2', '~> 0.2.11'
then:
然后:
$ cd RAILS_ROOT
$ gem uninstall mysql2
Select gem to uninstall:
1. mysql2-0.2.11
2. mysql2-0.3.6
3. All versions
> 3 # select "All versions"
$ rvm gemset install mysql2
$ bundle install
Now rails should start properly.
现在 rails 应该可以正常启动了。
回答by maxkaplan
This also fixed the issue I had with:
这也解决了我遇到的问题:
Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (no such file to load -- active_record/connection_adapters/mysql2_adapter)
You actually need to run: gem install mysql2 and add the gem to your config.
您实际上需要运行: gem install mysql2 并将 gem 添加到您的配置中。
回答by supriya
just run "gem install mysql" also add the same in gemfile and run bundle. worked
只需运行“gem install mysql”并在 gemfile 中添加相同的内容并运行 bundle。工作过
回答by Ritesh Kumar
If anybody still facing problem of installing mysql2 gem with rails 3 on Windows, then refer to the detailed steps of installation on -
如果有人仍然面临在 Windows 上使用 rails 3 安装 mysql2 gem 的问题,请参阅安装的详细步骤 -
http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html
http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html
回答by Tim
I'm a beginner at ruby, rails, and linux. So if this solution did not work, I hold no responsibility :)
我是 ruby、rails 和 linux 的初学者。所以如果这个解决方案不起作用,我不承担任何责任:)
Step 1:
第1步:
sudo gem uninstall mysql2
Step 2:
第2步:
sudo gem install mysql -v 0.2.7
Start webrick, if the same problem still appears reinstall rails.
启动webrick,如果还是出现同样的问题重新安装rails。
This solution works for me.
这个解决方案对我有用。
回答by connie
Same issue for me too. Upgraded to Rails 3.1.rc4 then downgraded to 3.0.3. Worked for me.
对我来说也是同样的问题。升级到 Rails 3.1.rc4 然后降级到 3.0.3。为我工作。
回答by Rafael Perea
as of 0.3.0, and ActiveRecord 3.1 - the ActiveRecord adapter has been pulled out of this gem and into ActiveRecord itself. If you need to use mysql2 with Rails versions < 3.1 make sure and specify gem "mysql2", "~> 0.2.7" in your Gemfile
从 0.3.0 和 ActiveRecord 3.1 开始 - ActiveRecord 适配器已从这个 gem 中拉出并进入 ActiveRecord 本身。如果您需要在 Rails 版本 < 3.1 中使用 mysql2,请确保并在您的 Gemfile 中指定 gem "mysql2", "~> 0.2.7"
the missing file (no such file to load
) can be found in the pre 0.3.0 versions of mysql2.
丢失的文件 ( no such file to load
) 可以在 mysql2 的 0.3.0 之前的版本中找到。
quoted from the documentation of mysql2