`block in replace_gem': Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter`

在执行rails s时出现“`block in replace_gem': Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter`”错误:

diudiugirl@DIUs:/var/www/ashelf$ rails s
=> Booting WEBrick
=> Rails 3.2.22.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/bundler-1.11.2/lib/bundler/rubygems_integration.rb:314:in `block in replace_gem': Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (can't activate mysql2 (~> 0.3.10), already activated mysql2-0.4.2. Make sure all dependencies are added to Gemfile.) (LoadError)
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activerecord-3.2.22.1/lib/active_record/connection_adapters/mysql2_adapter.rb:3:in `<top (required)>'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activesupport-3.2.22.1/lib/active_support/dependencies.rb:251:in `require'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activesupport-3.2.22.1/lib/active_support/dependencies.rb:251:in `block in require'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activesupport-3.2.22.1/lib/active_support/dependencies.rb:236:in `load_dependency'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activesupport-3.2.22.1/lib/active_support/dependencies.rb:251:in `require'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activerecord-3.2.22.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:50:in `resolve_hash_connection'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activerecord-3.2.22.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activerecord-3.2.22.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activerecord-3.2.22.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activerecord-3.2.22.1/lib/active_record/railtie.rb:88:in `block (2 levels) in <class:Railtie>'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activesupport-3.2.22.1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activesupport-3.2.22.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activesupport-3.2.22.1/lib/active_support/lazy_load_hooks.rb:26:in `block in on_load'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activesupport-3.2.22.1/lib/active_support/lazy_load_hooks.rb:25:in `each'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activesupport-3.2.22.1/lib/active_support/lazy_load_hooks.rb:25:in `on_load'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activerecord-3.2.22.1/lib/active_record/railtie.rb:80:in `block in <class:Railtie>'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/railties-3.2.22.1/lib/rails/initializable.rb:30:in `instance_exec'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/railties-3.2.22.1/lib/rails/initializable.rb:30:in `run'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/railties-3.2.22.1/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/railties-3.2.22.1/lib/rails/initializable.rb:54:in `each'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/railties-3.2.22.1/lib/rails/initializable.rb:54:in `run_initializers'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/railties-3.2.22.1/lib/rails/application.rb:136:in `initialize!'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/railties-3.2.22.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /var/www/ashelf/config/environment.rb:5:in `<top (required)>'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activesupport-3.2.22.1/lib/active_support/dependencies.rb:251:in `require'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activesupport-3.2.22.1/lib/active_support/dependencies.rb:251:in `block in require'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activesupport-3.2.22.1/lib/active_support/dependencies.rb:236:in `load_dependency'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/activesupport-3.2.22.1/lib/active_support/dependencies.rb:251:in `require'
from /var/www/ashelf/config.ru:3:in `block in <main>'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/rack-1.4.7/lib/rack/builder.rb:51:in `instance_eval'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/rack-1.4.7/lib/rack/builder.rb:51:in `initialize'
from /var/www/ashelf/config.ru:in `new'
from /var/www/ashelf/config.ru:in `<main>'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/rack-1.4.7/lib/rack/builder.rb:40:in `eval'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/rack-1.4.7/lib/rack/builder.rb:40:in `parse_file'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/rack-1.4.7/lib/rack/server.rb:200:in `app'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/railties-3.2.22.1/lib/rails/commands/server.rb:46:in `app'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/rack-1.4.7/lib/rack/server.rb:304:in `wrapped_app'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/rack-1.4.7/lib/rack/server.rb:254:in `start'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/railties-3.2.22.1/lib/rails/commands/server.rb:70:in `start'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/railties-3.2.22.1/lib/rails/commands.rb:55:in `block in <top (required)>'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/railties-3.2.22.1/lib/rails/commands.rb:50:in `tap'
from /home/diudiugirl/.rvm/gems/ruby-2.3.0/gems/railties-3.2.22.1/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

 

解决方法:

在Gemfile中加入:

gem 'mysql2'
gem 'activerecord-mysql2-adapter'

再执行bundle install 即可。

posted @ 2016-02-01 11:28  Sophiawow  Views(807)  Comments(0Edit  收藏