Rails 4.2无法读取Database.yml的环境变量
问题描述:
我的database.yml文件似乎未正确拾取环境变量.当我直接输入密码时,没有任何问题,因此我知道这不是密码问题.我还重新启动了服务器.
My database.yml file does not seem to be picking up the environment variable correctly. When I put the password in directly, there are no issues, so I know it's not a password problem. I've also restarted the server.
此外,当我在服务器上启动IRB并输入ENV ["DB_PASSWORD"时,它会返回:
Also, when I launch IRB on the server and type in ENV["DB_PASSWORD" it is returned:
2.2.0 :001 > ENV["DB_PASSWORD"]
=> "tej-wir-alt-od-yirf-aj-yam-yis-ed-an-buc"
database.yml
database.yml
production:
database: myapp
username: root
password: <%= ENV["DB_PASSWORD"] %>
host: localhost
adapter: mysql2
port: 3306
pool: 15
timeout: 5000
.bashrc
export MYSQL_DB=tej-wir-alt-od-yirf-aj-yam-yis-ed-an-buc
答
您可以在.profile中设置变量,因为它会在每次重新引导服务器时加载.
You can set variable in .profile because it will load every time while you will reboot server.
您可以通过以下步骤添加:
You can add with following step:
打开 sudo nano〜/.profile
然后添加变量
export DB_PASSWORD=tej-wir-alt-od-yirf-aj-yam-yis-ed-an-buc
然后使用以下方式重新加载配置文件
Then reload profile with
. ~/.profile
这将是可行的.