【发布时间】:2013-05-02 16:46:40
【问题描述】:
在 Windows 7 上使用 WEBrick 启动我的 rails 服务器时出现以下错误:
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/rubygems_integ
ration.rb:214:in block in replace_gem': Please install the mysql2 adapter:gem
安装 activerecord-mysql2-adapter`(mysql2 不是捆绑包的一部分。添加它
到 Gemfile。)(加载错误)
我已确定 database.yml 的适配器为 mysql2,gemfile 列出了 mysql2。下面是我的 database.yml 文件和 gem 文件
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: elearn3_development
pool: 5
username: root
password: password
host: 127.0.0.1
port: 3306
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: elearn3_test
pool: 5
username: root
password: passsword
host: 127.0.0.1
port: 3306
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: elearn3_production
pool: 5
username: root
password: passsword
host: 127.0.0.1
port: 3306
宝石文件: 源'https://rubygems.org'
gem 'rails', '3.2.13'
# 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'
我已经尝试了在其他线程中发布的具有相同问题的所有各种选项,例如添加 gem 'mysql2' 'version no'。它不能解决问题。我在发布 sql-lite 时也遇到了同样的问题。
感谢您的帮助。提前致谢。
编辑:当我运行捆绑安装时,我会在窗口中看到以下内容。请注意 mysql2 不是使用列表的一部分。这正常吗?
Using rake (10.0.4)
Using i18n (0.6.1)
Using multi_json (1.7.2)
Using activesupport (3.2.13)
Using builder (3.0.4)
Using activemodel (3.2.13)
Using erubis (2.7.0)
Using journey (1.0.4)
Using rack (1.4.5)
Using rack-cache (1.2)
Using rack-test (0.6.2)
Using hike (1.2.2)
Using tilt (1.4.0)
Using sprockets (2.2.2)
Using actionpack (3.2.13)
Using mime-types (1.23)
Using polyglot (0.3.3)
Using treetop (1.4.12)
Using mail (2.5.3)
Using actionmailer (3.2.13)
Using arel (3.0.2)
Using tzinfo (0.3.37)
Using activerecord (3.2.13)
Using activeresource (3.2.13)
Using coffee-script-source (1.6.2)
Using execjs (1.4.0)
Using coffee-script (2.2.0)
Using rack-ssl (1.3.3)
Using json (1.7.7)
Using rdoc (3.12.2)
Using thor (0.18.1)
Using railties (3.2.13)
Using coffee-rails (3.2.2)
Using jquery-rails (2.2.1)
Using bundler (1.3.5)
Using rails (3.2.13)
Using sass (3.2.8)
Using sass-rails (3.2.6)
Using uglifier (2.0.1)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
编辑 在尝试了http://www.mohanarun.com/how-to-install-mysql-adapter-ruby-gem-in-windows/ 的说明后,我看到捆绑安装正在获取 mysql。但是,当我做 rails server 时,我得到了以下错误。
/* 之前还有很多错误 */
pport/core_ext/load_error.rb 369 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_su pport/core_ext/name_error.rb 370 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_su pport/core_ext/uri.rb 371 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/action_contr oller.rb 372 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/action_view/ railtie.rb 373 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/abstract_con troller/railties/routes_helpers.rb 374 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/action_contr oller/railties/paths.rb 375 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/action_contr oller/railtie.rb 376 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_rec ord/railtie.rb 377 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/actionmailer-3.2.13/lib/action_mai ler/version.rb 378 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_su pport/core_ext/class/delegating_attributes.rb 379 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_su pport/core_ext/module/reachable.rb 380 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_su pport/core_ext/class/subclasses.rb 381 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_su pport/core_ext/class.rb 382 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_su pport/core_ext/array/uniq_by.rb 383 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/actionmailer-3.2.13/lib/action_mai ler.rb 384 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/actionmailer-3.2.13/lib/action_mai ler/railtie.rb 385 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activeresource-3.2.13/lib/active_r 资源/异常.rb 386 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activeresource-3.2.13/lib/active_r 资源/version.rb 387 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activeresource-3.2.13/lib/active_r 资源.rb 388 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activeresource-3.2.13/lib/active_r 资源/railtie.rb 389 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/test_uni t/railtie.rb 390 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/sprockets/ra iltie.rb 391 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/all.rb 392 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_su pport/string_inquirer.rb 393 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11/lib/mysql2/version.r b 394 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11/lib/mysql2/error.rb 395 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11/lib/mysql2/result.rb
[注意] 您可能在 Ruby 解释器或扩展库中遇到了错误。 欢迎提交错误报告。 详情:错误报告
此应用程序已请求运行时以不寻常的方式终止它。 请联系应用程序的支持团队了解更多信息。
【问题讨论】:
-
您是否运行
bundle install来安装您的 Gemfile 中列出的 gem? -
是的,我用信息更新了问题。 mysql2 不属于使用列表的一部分。有问题吗?
-
双重和三重检查
gem 'mysql2'没有在您的 Gemfile 中注释掉。如果没有,则运行gem list mysql并查看gem 是否已安装在您的系统上。如果没有,请运行gem install mysql2并报告。 -
gem mysql2 未被注释掉,gem list mysql 显示 mysql2 (0.2.6)。我也尝试安装mysql2(0.3.11)但没有成功。我可以在我的 gem 目录中看到活动记录适配器 mysql2 gem 文件夹:C:\Ruby200-x64\lib\ruby\gems\2.0.0\gems