【问题标题】:Booting up Rails for the first time, "Please install mysql2 adapter"首次启动 Rails,“请安装 mysql2 适配器”
【发布时间】:2013-04-09 03:48:48
【问题描述】:

我已经成功运行了 mysql2 install (3.11) 并且 activerecord-mysql2-adapter 在我的 gem 列表中。当我创建新项目时,我已经运行了 bundle install 。

C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/rubygems_integration.rb:214:in 'block in replace_gem': Please install the mysql2 adapter: 'gem install activerecord-mysql2-adapter' (mysql2 is not part of the bundle. Add it to Gemfile.) (LoadError)

请帮助我,我什至无法让 Rails 服务器运行。我的其他程序会阻塞导轨或防火墙吗?如果可以,我可以在防火墙中允许什么程序?

我的 Gemfile 指定以下内容。

    source 'https://rubygems.org'

gem 'rails'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'mysql2'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

我生成的错误在这里

Exiting
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/rubygems_integration.rb:214:in `block in replace_gem': Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (mysql2 is not part of the bundle. Add it to Gemfile.) (LoadError)
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:3:in `<top (required)>'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:50:in `resolve_hash_connection'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'

    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:42:in `each'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/base.rb:720:in `<top (required)>'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/railtie.rb:88:in `block in <class:Railtie>'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/i
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from C:/Users/Charlie/Documents/RailsProject/shop/config/environment.rb:5:in `<top (required)>'
    from C:/Users/Charlie/Documents/RailsProject/shop/config.ru:3:in `require'
    from C:/Users/Charlie/Documents/RailsProject/shop/config.ru:3:in `block in <main>'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rack1.4.5/lib/rack/builder.rb:51:in`instance_eval'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rack-1.4.5/lib/rack/builder.rb:51:in`initialize'
    from C:/Users/Charlie/Documents/RailsProject/shop/config.ru:in `new'
    from C:/Users/Charlie/Documents/RailsProject/shop/config.ru:in `<main>'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rack-1.4.5/lib/rack/builder.rb:40:in`parse_file'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties3.2.13/lib/rails/commands/server.rb:46:in `app'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rack-1.4.5/lib/rack/server.rb:304:in`wrapped_app'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties3.2.13/lib/rails/commands/server.rb:70:in `start'        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/commands.rb:55:in `block in <top (required)>'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

【问题讨论】:

  • adapter 设置在您的config/database.yml 中说明了什么?
  • 当我的 database.yml 有 mysql 而 gemfile 有 mysql2 或反之亦然时,我会遇到类似的奇怪错误。
  • ITs mysql2,正确。我需要已经创建的数据库表吗?或者这是否为我创建了一个数据库(rails 服务器)

标签: ruby-on-rails ruby ruby-on-rails-3 debugging compiler-errors


【解决方案1】:

您必须确保您的database.yml 文件是正确的。 你应该有

adapter: mysql2 不是mysql/anything

谢谢。

【讨论】:

    【解决方案2】:

    请检查你的 config/database.yml 文件,你的结构应该是这样的

    development:
      adapter: mysql2
      encoding: utf8
      reconnect: false
      database: abc_development
      pool: 5
      username: your_database_username
      password: your_database_password
      host: localhost
    

    适用于所有 3 种环境

    最重要的是,你应该为此创建你的mysql数据库,你的系统上安装了mysql。给你的数据库提供用户名和密码,并将其添加到你的database.yml文件中

    【讨论】:

    • 我需要3个数据库吗? abc_development、abc_test、abc_production?
    • 哦,所以我必须先创建一个数据库才能运行rails server
    • 创建数据库的命令是什么?我是否要启动 MySQL Command Shell,登录并执行Create database projectname
    猜你喜欢
    • 2013-05-09
    • 2013-01-16
    • 2012-04-04
    • 2013-03-15
    • 1970-01-01
    • 2012-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多