[英]rails database_url escaping mysql2 url passwod
So I am trying to set an environment variable for my rails production environment database as suggested in the .yml file. 因此,我试图按照.yml文件中的建议为我的Rails生产环境数据库设置一个环境变量。 In my .bash_profile I export it like this:
在我的.bash_profile中,我将其导出为:
export DATABASE_URL=mysql2://<username>:<password>@localhost/<database>
I go to my website and i get " ActiveRecord::AdapterNotSpecified
" error. 我转到我的网站,并收到“
ActiveRecord::AdapterNotSpecified
”错误。
The only thing I can think of is that my password ends in an @ sign which would make the url have @@ and get confused where the password ends and the host begins? 我唯一能想到的是我的密码以@符号结尾,这会使url具有@@并在密码结尾和主机开始的地方感到困惑?
Also this app is hosted on Hostmonster if that helps 此外,如果有帮助,此应用程序也可以托管在Hostmonster上
database.yml: 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"] %>
You may need to include the default part as well: 您可能还需要包括默认部分:
production:
<<: *default
If your password has an @
in it, try encoding it for a URL: 如果您的密码中包含
@
,请尝试将其编码为URL:
password%40
That could be the thing. 可能就是这样。 Either that or pick a password that's URL-friendly.
要么选择一个URL友好的密码。
As a note, it's usually best to host the database.yml
file for production exclusively on the target server, then symlink it in when you deploy the application. 需要注意的是,通常最好只在目标服务器上托管用于生产的
database.yml
文件,然后在部署应用程序时将其符号链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.