mysql - Rails 无法使用 rake db :create?

标签 mysql ruby-on-rails ruby

我遵循了本教程:http://cicolink.blogspot.nl/2011/06/how-to-install-ruby-on-rails-3-with.html我正在做以下事情:

$ rails new ourapp -d=mysql
$ cd ourapp/
$ rake:dbcreate/

我的 gemfile 是:

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'

# Use mysql as the database for Active Record
gem 'mysql2', '~> 0.2.7'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

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

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

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

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

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

我收到以下错误:

rake aborted!
cannot load such file -- mysql2/mysql2
/root/Development/Rails/ourapp/config/application.rb:7:in `<top (required)>'
/root/Development/Rails/ourapp/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

这是一条轨迹:

rake db:create --trace
rake aborted!
cannot load such file -- mysql2/mysql2
/usr/local/lib/ruby/gems/2.0.0/gems/mysql2-0.2.20/lib/mysql2.rb:8:in `require'
/usr/local/lib/ruby/gems/2.0.0/gems/mysql2-0.2.20/lib/mysql2.rb:8:in `<top (required)>'
/usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
/usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
/usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
/usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
/usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
/usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
/usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
/root/Development/Rails/ourapp/config/application.rb:7:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/2.0.0/rubygems/custom_require.rb:36:in `require'
/usr/local/lib/ruby/site_ruby/2.0.0/rubygems/custom_require.rb:36:in `require'
/root/Development/Rails/ourapp/Rakefile:4:in `<top (required)>'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load_rakefile'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:637:in `raw_load_rakefile'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:94:in `block in load_rakefile'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:93:in `load_rakefile'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:77:in `block in run'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'

我该如何解决这个问题?

最佳答案

尝试使用 gem update --system 更新 RubyGems(Ruby 2.0 上的 RubyGems 1.8.x 存在错误)

关于mysql - Rails 无法使用 rake db :create?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19481840/

相关文章:

mysql - Laravel 中的条件 `orderBy` 或 `DB::Raw` inside `orderBy`

html - MYSQL:显示正确的记录

ruby-on-rails - 将字符串与 rspec 中的正则表达式进行比较?

ruby-on-rails - Rails 4 不同 View 的片段缓存

ruby - 从使用示例中实现一个类

ruby-on-rails - 难以理解在 Ruby 类的初始化(构造函数)中使用 self 和 @ 之间的区别

ruby-on-rails - 来自 rake 任务的抽象逻辑

java - SQL语句(排序依据)

php - magento 1.5 产品评论存储在哪里?

ruby-on-rails - JSON::ParserError: 757: '{ 处的意外标记