试图以root身份访问db的HostMonster上托管的Rails应用程序

时间:2014-04-10 16:49:07

标签: ruby-on-rails ruby ruby-on-rails-4 passenger

所以这是我的database.yml:

default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: root

development:
  <<: *default
  database: test

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: vollapp_test

# Avoid production credentials in the repository,
# instead read the configuration from the environment.
#
# Example:
#   mysql2://myuser:mypass@localhost/somedatabase
#
production:
  adapter: mysql2
  url: <%= ENV["DATABASE_URL"] %>

在我的生产服务器上,由hostmonster托管,我收到500错误,生产日志显示为Mysql2::Error (Access denied for user 'root'@'localhost')。关于这一点的奇怪之处在于我的DATABASE_URL甚至没有使用&#39; root&#39;作为用户。 我知道这实际上可能是重复的,但我已经尝试了我在此发现的所有其他问题的所有答案,但没有一个适合我/适合我。 rake db:migrate对我来说很好。老实说,我很难过。

1 个答案:

答案 0 :(得分:1)

除了URL方法之外,您可能还需要完整地拼出配置参数:

production:
  adapter: mysql2
  username: username
  password: password
  host: hostname
  database: databasename
  url: <%+ ENV["DATABASE_URL"] %>

我希望他们在未来版本的Rails中实际解析url值,因为这似乎是一些重复的工作。

config/database.yml的任何更改都需要重新启动Rails进程。