On my local machine, I want to set environment variables for all of the sensitive information in the database.yml file. My file looks like this:
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: <%= ENV['DATABASE_USERNAME'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
socket: <%= ENV['SOCKET'] %>
development:
<<: *default
database: <%= ENV['DEVELOPMENT_DATABASE'] %>
test:
<<: *default
database: #JetStreamIQ-2_0_test
production:
<<: *default
database: <%= ENV['PRODUCTION_DATABASE'] %>
username: <%= ENV['DATABASE_USERNAME'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
I thought that I could just set these environment variables in my .bashrc file, but that doesn't seem to be working. My .bashrc file looks like this:
export DATABASE_USERNAME="root"
export DATABASE_PASSWORD="*****"
export SOCKET="/var/run/mysqld/mysqld.sock"
export DEVELOPMENT_DATABASE="shoppe_development"
export PRODUCTION_DATABASE="#"
When I run my server with
rails s
I get an error that says:
Access denied for user 'root'@'localhost' (using password: YES)
I understand that there is a problem with the database username and password because of the way I've configured my database.yml file, but I'm just not sure what it is.
Is there something big I'm missing here? Any help would be much appreciated.
Thanks!
I'd like to offer a couple of tips here.
You can run database.yml through erb to test what you're getting. For example, erb config/database.yml
. This will help you determine what the problem may be.
You can find out every environment variable set in your shell with the set
command. This will allow you to confirm that the environment variables you're expecting are being set (in .bashrc
).
Hope this is helpful.
It turns out that after I edited my bashrc file, I needed to exit out of that terminal session and open another terminal for the changes to be finalized :/ After I did that my application started perfectly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With