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:14

I never would have believed it but deleting my database.yml file and recreating it actually solved the problem for me too. Thanks Tyler. I spent hours installing and uninstalling different versions of the gems mysql, mysql2, activerecord-mysql-adapter, etc... In the end, my gemfile has

gem 'mysql2', "~>0.3.11"

and my database.yml file has

adapter: mysql2

I am on OSX 10.8, rails 3.2.8, and ruby 1.9.3.

By the way, I experienced the same issues with the mysql2 adapter on my Windows 7 machine. Uninstalling and even deleting the directory for the activerecord-mysql-adapter gem seemed to be critical as well.

查看更多
萌系小妹纸
3楼-- · 2019-02-02 20:15

For a old rails 2.3.18 ruby 1.8.7 app that I 'migrated' to a new MacBook (High Sierra - 10.13.6), in order to get the app to run (using POW) and to use script/console, I had to disable SIP and create a link to a file in /urs/lib/ directory. Migration Assistant was unable to create the link because of SIP.

To Disable SIP - System Integrity Protection

  1. Boot into Mac OS Recovery Mode as usual by holding down the Command and R keys during system start.

  2. Choose the language as usual (if applicable)

  3. At the “MacOS Utilities” screen, pull down the “Utilities” menu from the top of the screen.

  4. In terminal, type command: csrutil disable

  5. Restart your computer

Finally, after restarting, in Terminal enter this command:

sudo ln /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

查看更多
The star\"
4楼-- · 2019-02-02 20:18

It is possible that you have changed adapter to mysql2 for a certain environment only but are not passing the environment to the rake command.

E.g. I only changed mysql to mysql2 on the production environment but was running

rake generate_secret_token

when I changed it to the following it worked:

rake generate_secret_token RAILS_ENV=production
查看更多
家丑人穷心不美
5楼-- · 2019-02-02 20:19

you have mentioned your database.yaml file already has mysql2.

Its worth checking if you have activerecord-mysql2-adapter installed. (Note -mysql2- )

查看更多
闹够了就滚
6楼-- · 2019-02-02 20:20

You want to install the mysql2 gem.

Really, you should probably add it to your Gemfile:

gem "mysql2"

And then install your gems with bundler:

bundle install
查看更多
何必那么认真
7楼-- · 2019-02-02 20:23

Step 1. gem 'mysql2', "~>0.3.11" instead of gem 'mysql2' in Gemfile

Step 2. putting mysqllib.dll (available at mysql installation C:\wamp\bin\mysql\mysql5.5.24\lib ) in the C:\ruby2.0.0\bin folder solved the rake db:migrate problem and successfully connected my rails with mysql (database.yml contains mysql2)

I'm running windows 7, 64bit, mysql 64bit, ruby 2.0.0 [x64-mingw32]

Thanks you all for your inputs.

查看更多
登录 后发表回答