rails mysql 适配器错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6141276/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:03:23  来源:igfitidea点击:

rails mysql adapter error

mysqlruby-on-rails-3.1

提问by codr

I'm having trouble finding a solution to this problem. I'm getting the error

我无法找到解决此问题的方法。我收到错误

Please install the mysql adapter: 'gem install activerecord-mysql-adapter'

请安装mysql适配器:'gem install activerecord-mysql-adapter'

when I specify either ruby-mysqlor mysql2in my Gemfile. This has only happened since I've upgraded to Rails 3.1.0-rc1. I'm running OSX 10.6, Ruby 1.9.2.

当我指定ruby-mysqlmysql2在我的Gemfile. 这只是在我升级到 Rails 3.1.0-rc1 后才发生的。我正在运行 OSX 10.6,Ruby 1.9.2。

cody$ rails c
/Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `rescue in establish_connection': Please install the mysql adapter: `gem install activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile.) (RuntimeError)
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/connection_specification.rb:68:in `establish_connection'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/connection_specification.rb:60:in `establish_connection'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc1/lib/active_record/railtie.rb:69:in `block (2 levels) in <class:Railtie>'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc1/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc1/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc1/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc1/lib/active_record/base.rb:2135:in `<top (required)>'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc1/lib/active_record/railtie.rb:34:in `block in <class:Railtie>'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/railtie.rb:177:in `call'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/railtie.rb:177:in `block in load_console'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/railtie.rb:177:in `each'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/railtie.rb:177:in `load_console'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/application.rb:115:in `block in load_console'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/application/railties.rb:8:in `each'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/application/railties.rb:8:in `all'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/application.rb:115:in `load_console'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/commands/console.rb:26:in `start'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/commands/console.rb:8:in `start'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

Here is the gem envoutput

这是gem env输出

cody$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.6.2
- RUBY VERSION: 1.9.2 (2011-02-18 patchlevel 180) [x86_64-darwin10.7.3]
- INSTALLATION DIRECTORY: /Users/cody/.rvm/gems/ruby-1.9.2-p180
- RUBY EXECUTABLE: /Users/cody/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
- EXECUTABLE DIRECTORY: /Users/cody/.rvm/gems/ruby-1.9.2-p180/bin
- RUBYGEMS PLATFORMS:
  - ruby
  - x86_64-darwin-10
- GEM PATHS:
   - /Users/cody/.rvm/gems/ruby-1.9.2-p180
   - /Users/cody/.rvm/gems/ruby-1.9.2-p180@global
- GEM CONFIGURATION:
   - :update_sources => true
   - :verbose => true
   - :benchmark => false
   - :backtrace => false
   - :bulk_threshold => 1000
   - :sources => ["http://gems.rubyforge.org/", "http://gems.github.com"]
- REMOTE SOURCES:
   - http://gems.rubyforge.org/
   - http://gems.github.com

采纳答案by christianparpart

I had to enforce the use of mysql2 gem version 0.2.7 and while trying to upgrade my rails 3.0.7 app to 3.1.0.rc1, I also noticed ,that you'll need the following new gems in your Gemfile, too:

我不得不强制使用 mysql2 gem 版本 0.2.7,在尝试将我的 rails 3.0.7 应用程序升级到 3.1.0.rc1 时,我还注意到,您的 Gemfile 中也需要以下新 gem:

gem 'mysql2', '< 0.3' # as stated above

# Asset template engines
gem 'json'
gem 'sass'
gem 'coffee-script'
gem 'uglifier'
# other required things for rails 3.1
gem 'jquery-rails'
gem 'mustang' # this is ONE execjs backend of many, and the only one that worked for me.

Tell me if that worked for you.

告诉我这是否对你有用。

回答by Brad Folkens

You'll have to change your config/database.ymlto use the mysql2adapter instead of mysql.

您必须更改您config/database.yml的使用mysql2适配器而不是mysql.

So replace:

所以替换:

adapter: mysql

With:

和:

adapter: mysql2

回答by Josh Harris

Fixed the problem by updating the gemfile for my app to identify mysql2 as part of the bundle.

通过更新我的应用程序的 gemfile 以将 mysql2 识别为捆绑包的一部分来解决该问题。

To do this, navigate to the root of your app, run open gemfile

为此,导航到您的应用程序的根目录,运行 open gemfile

Add the line gem 'mysql2', '< 0.3.7'directly below the gem line for rails.

gem 'mysql2', '< 0.3.7'轨道的 gem线正下方添加该线。

While in terminal at the root of your app, run bundle install

在应用程序根目录的终端中,运行 bundle install

Run bundle show mysql2to verify the bundle worked. You should be good to go with the adapter now.

运行bundle show mysql2以验证捆绑包是否有效。您现在应该可以使用适配器了。

My environment is Rails 3.1, MySql 5.5, Ruby 1.9.2.

我的环境是 Rails 3.1、MySql 5.5、Ruby 1.9.2。

回答by user2128670

I created a Rails project on windows and moved it to a machine running Fedora. I solved this problem by renaming the "Gemfile.lock" to "old_Gemfile.lock". Of course, you must still specify the adapter as 'mysql2' and include the appropriate gem in your gemfile.

我在 Windows 上创建了一个 Rails 项目并将它移到运行 Fedora 的机器上。我通过将“Gemfile.lock”重命名为“old_Gemfile.lock”解决了这个问题。当然,您仍然必须将适配器指定为 'mysql2' 并在您的 gemfile 中包含适当的 gem。