Please install mysql adapter 'gem install acti

2019-02-02 19:41发布

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'

 /Users/ Andy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/rubygems_integration.rb:143:in `block in replace_gem': Please install the mysql adapter: `gem install activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile.) (LoadError)
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/mysql_adapter.rb:5:in `<top (required)>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:48:in `resolve_hash_connection'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:23:in `spec'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/railtie.rb:76:in `block (2 levels) in <class:Railtie>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/railtie.rb:74:in `block in <class:Railtie>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `run'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `each'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/application.rb:136:in `initialize!'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/ Andy /config/environment.rb:5:in `<top (required)>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/ Andy /config.ru:4:in `block in <main>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
    from /Users/ Andy /config.ru:1:in `new'
    from /Users/ Andy /config.ru:1:in `<main>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands/server.rb:46:in `app'
    from /Users/ Andy/mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands/server.rb:70:in `start'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:55:in `block in <top (required)>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:50:in `tap'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>' ```

Here is the gem env output.

  RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.15
  - RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [x86_64-darwin11.2.0]
  - INSTALLATION DIRECTORY: /Users/ Andy/.rvm/gems/ruby-1.9.2-p290
  - RUBY EXECUTABLE: /Users/ Andy/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/ Andy/.rvm/gems/ruby-1.9.2-p290/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-11
  - GEM PATHS:
     - /Users/ Andy/.rvm/gems/ruby-1.9.2-p290
     - /Users/ Andy/.rvm/gems/ruby-1.9.2-p290@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

If I can provide any more information please let me know.

Thanks, -Andy


P.s - My database.yaml already has mysql2.

标签: mysql mysql2
16条回答
孤傲高冷的网名
2楼-- · 2019-02-02 20:25

In my case, when I also got this error:

rake aborted! Please install the mysql adapter: gem install activerecord-mysql-adapter (mysql is not part of the bundle. Add it to Gemfile.)

After I searched Google and tried many ways, it didn't work. Finally, the answer is

  • Navigate to the root of your app, run open gemfile
  • Add the line gem 'mysql2', '< 0.3.7' directly below the gem line for rails.
查看更多
冷血范
3楼-- · 2019-02-02 20:27

I had the same problem as OP on OSX Lion after upgrading to Rails 3.2. Removing all gems, bundle install, etc did not work. Gemfile and database.yml were correctly specifying mysql2.

In the end, I deleted and recreated my database.yml and everything works again. It was probably a typo or hidden character in the file.

查看更多
啃猪蹄的小仙女
4楼-- · 2019-02-02 20:27

If nothing helps (you have mysql2 as adapter in your database.yml) and you are using RVM to manage your ruby versions, here is the simplest solution:

Try to remove all of your old gemsets (including global), install a fresh ruby version and bundle again. I could solve the problem that way.

查看更多
家丑人穷心不美
5楼-- · 2019-02-02 20:32

I would say that change the commented information on top in database.yml to

# 
# Install the MYSQL driver
#   gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
#   gem 'mysql2'
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html

second: add " gem 'mysql2' " (what ever is inside the double quotation marks) to gemfile .

save everything, do bundle install. Hope that helps.

or it just could be a typo.

查看更多
相关推荐>>
6楼-- · 2019-02-02 20:34

This might be late but bundle install was installing 0.4.0 So I tried to edit the gem file and I replace mysql2 with

gem 'mysql2', "~>0.3.11"

and then

bundle install

in the terminal (This will install mysql2 0.3.11 and not the last version) I think active record have problems working with the last version. Well I hope it helps

查看更多
看我几分像从前
7楼-- · 2019-02-02 20:36

I just added the following line to my Gemfile an it worked:

gem "mysql"

Before:

source 'https://rubygems.org'

gem "rails", "3.2.16"
gem "jquery-rails", "~> 2.0.2"
gem "coderay", "~> 1.1.0"
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"
...

After:

source 'https://rubygems.org'

gem "mysql"
gem "rails", "3.2.16"
gem "jquery-rails", "~> 2.0.2"
gem "coderay", "~> 1.1.0"
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"
...
查看更多
登录 后发表回答