rails database_url正在转义mysql2 url密码



因此,我正试图按照.yml文件中的建议为rails生产环境数据库设置一个环境变量。在我的.bash_profile中,我这样导出它:

export DATABASE_URL=mysql2://<username>:<password>@localhost/<database>

我去我的网站,我得到"ActiveRecord::AdapterNotSpecified"错误。

我唯一能想到的是,我的密码以@符号结尾,这会使url具有@@,并混淆密码的结尾和主机的开头?

此外,这个应用程序托管在Hostmonster上,如果这有助于

database.yml:

default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: <username>
  password: <password>
  database: <database>
development:
  <<: *default
  database: <database>
# 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: <database>
# Avoid production credentials in the repository,
# instead read the configuration from the environment.
#
# Example:
#   mysql2://myuser:mypass@localhost/somedatabase
#
production:
  url: <%= ENV["DATABASE_URL"] %>

您可能还需要包括默认部分:

production:
  <<: *default

如果您的密码中有@,请尝试将其编码为URL:

password%40

可能就是这样。或者选择一个URL友好的密码。

需要注意的是,通常最好在目标服务器上专门承载用于生产的database.yml文件,然后在部署应用程序时将其符号链接进来。

最新更新