1

我正在使用 ruby​​ 版本 1.9.3 p448 和 rails 版本 3.2.13 我所有的 gem 都是最新的。

我用以下代码创建一个项目rails new simple_cms -d mysql

但是当我用代码启动rails服务器时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 中,你应该为你的数据库指定密码。例如:如果您已将 devlopment 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 回答