1

Ruby バージョン 1.9.3 p448 と Rails バージョン 3.2.13 を使用しています。私の宝石はすべて最新です。

次のコードでプロジェクトを作成しますrails new simple_cms -d mysql

しかし、コードrails s/でレールサーバーを起動するとrails server

次のエラーが発生しました

wasif@Bayaw:~/projects/Sites/simple_cms$ rails s
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in `connect': Access denied for user 'root'@'localhost' (using password: NO) (Mysql2::Error)
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in `initialize'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
    from /home/wasif/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
    from /home/wasif/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/railtie.rb:88:in `block in <class:Railtie>'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /home/wasif/projects/Sites/simple_cms/config/environment.rb:5:in `<top (required)>'
    from /home/wasif/projects/Sites/simple_cms/config.ru:3:in `require'
    from /home/wasif/projects/Sites/simple_cms/config.ru:3:in `block in <main>'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
    from /home/wasif/projects/Sites/simple_cms/config.ru:in `new'
    from /home/wasif/projects/Sites/simple_cms/config.ru:in `<main>'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/commands/server.rb:46:in `app'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/commands/server.rb:70:in `start'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/commands.rb:55:in `block in <top (required)>'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
    from /home/wasif/.rvm/gems/ruby-1.9.3-p448/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>'

このエラーを解決する方法を教えてください...ありがとう!

4

1 に答える 1

0

パスワードが設定されていないようです。database.yml で、DB のパスワードを指定する必要があります。例: 開発用 PC のパスワードを root に設定した場合、次のようになります。

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: your_db_name
  pool: 5
  username: root
  password: root
  socket: 'depending on your os something like:' /tmp/mysql.sock

また、このファイルを VCS にチェックインしないことをお勧めします。それのコピーを作成し、それを database.example.yml と呼び、そこに構成とパスワードのプレースホルダーを入れます。

于 2013-08-12T07:46:57.930 に答える