如果不是root,则忽略database.yml文件中的用户名和密码

时间:2013-09-26 21:56:16

标签: ruby-on-rails ruby

我正在尝试运行一个RoR应用程序,它似乎忽略了我的用户名和密码,如果它不是root,有什么想法吗?

如果配置如下,则可以:

development:
  adapter: mysql2
  database: dbname
  user: root
  password: root_password
  pool: 5
  timeout: 5000

但是,如果它是使用非root用户设置的,则会失败并显示消息`connect':用户'root'@ accesshost'拒绝访问(使用密码:YES)(Mysql2 :: Error) )

development:
  adapter: mysql2
  database: dbname
  user: username
  password: username_password
  pool: 5
  timeout: 5000

mysql -uusername -p<username password> <dbname>连接没有任何问题。指定hosthostname无法解决问题。

更新

的database.yml

development:
  adapter: mysql2
  database: dbname
  user: root
  # username
  password: root_password
  # username_password
  pool: 5
  timeout: 5000

production:
  adapter: mysql2
  database: dbname
  user: username
  password: username_password
  pool: 5
  timeout: 5000

运行RAILS_ENV=development bundle exec rails c

的结果
Loading development environment (Rails 3.2.11)
irb(main):001:0>

1 个答案:

答案 0 :(得分:2)

我的database.yml已过时(设置不正确)。 user不是正确的密钥,而是username

development:
  adapter: mysql2
  database: dbname
  username: root
  # username
  password: root_password
  # username_password
  pool: 5
  timeout: 5000

production:
  adapter: mysql2
  database: dbname
  username: username
  password: username_password
  pool: 5
  timeout: 5000