【问题标题】:Rails app hosted on HostMonster trying to access db as root托管在 HostMonster 上的 Rails 应用程序试图以 root 身份访问数据库
【发布时间】:2014-04-10 16:49:06
【问题描述】:

这是我的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 甚至没有使用“root”作为用户。 我知道这实际上可能是重复的,但我已经尝试了我在此找到的所有其他问题的所有答案,但没有一个适合/适合我。 rake db:migrate 对我来说很好。老实说,我很难过。

【问题讨论】:

  • 我不确定url 是否包含连接所需的所有信息。您可能必须单独分解参数。见:example
  • 我居然把所有的url信息都爆出来了,把你添加的链接里的信息都包含进去了,还是不行。
  • 没关系...我忘记触摸 tmp/restart.txt 来重新启动乘客...这有效。希望我能找到一种方法将信息放入环境变量中,就像默认设置一样。
  • 啊,这是个老生常谈的问题。在开发模式下,Rails 将始终适应 app/config/routes.rb 中任何内容的更改,但其他任何内容都需要 restart.txt 技巧。

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


【解决方案1】:

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

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

我希望他们在未来版本的 Rails 中真正解析 url 值,因为这似乎有点重复。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-10
    • 2017-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-06
    • 2015-06-07
    相关资源
    最近更新 更多