首页 文章

我在localhost上运行服务器时出现问题(ruby on rails)

提问于
浏览
1

当我在我的CMD中键入rails服务器时服务器工作,我可以转到localhost:3000 . 但是我在CMD中获得了这个消息,并且在错误部分的localhost:3000上的浏览器中显示了相同的消息 .

Started GET "/rails/info/properties" for 127.0.0.1 at 2010-12-02 21:14:55 +0200

Mysql2::Error (Access denied for user 'root'@'localhost' (using password: NO)):

Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/_request_and_response.erb (30.0ms)
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/diagnostics.erb within rescues/layout (97.0ms)

有什么问题?

这是database.yml文件:

#MySQL . 建议使用版本4.1和5.0 . ##安装MySQL驱动程序:#gem install mysql2 ##并确保使用新式密码哈希:#http://dev.mysql.com/doc/refman/5.0/en/old-client.html开发: adapter:mysql2编码:utf8 reconnect:false database:simple_cms_development pool:5用户名:root密码:host:localhost#警告:定义为“test”的数据库将被删除,
#在运行时从您的开发数据库重新生成
“耙” . #不要将此db设置为与开发或 生产环境 相同 . test:adapter:mysql2编码:utf8 reconnect:false database:simple_cms_test pool:5用户名:root密码:host:localhost production:
适配器:mysql2
编码:utf8
重新连接:false
database:simple_cms_production
游泳池:5
用户名:root
密码:passwordex
主持人:localhost

2 回答

  • 3

    您正在为您的mysql用户使用root,但不在config / database.yml中提供root密码 .

    顺便提一下,虽然它通常可以开发,但是在 生产环境 中使用root mysql用户或者进行分段是一个非常糟糕的想法 .

    这是一个典型的mysql配置部分:

    production:
      adapter: mysql
      database: app_production
      username: root
      password: password
      pool: 5
      timeout: 5000
      encoding: utf8
    
  • 1

    我知道你已经找到了你的问题的解决方案,但无论如何我会发布这个答案,对于那些可能会遇到同样问题的人 .

    有完全相同的 Access denied for user 'user'@'localhost' (using password: NO) 问题,事实证明我的 database.yml 文件格式错误 . 原因? YAML没有't allow certain characters: I happened to be using a '!'在我的密码中,无论出于何种原因,读取此 database.yml 文件的YAML解析器忽略了我的密码行,就像它不存在一样,因此 (using password: NO) ,即使我已明确声明它 .

    解?更改了我的密码,不包括任何YAML特殊字符 . 不过,我想可能有办法逃脱它 . 尽管很恼火 .

相关问题