1

Hello all I am trying to use a command -

rake db:migrate

but I am getting this as feedback in the terminal -

rake aborted!
Mysql2::Error: Access denied for user 'root'@'localhost' (using password: NO)

I'm looking to have something to request the password when I use the command, such as

rake db:migrate -p

but this isn't working for me I've tried various things like putting it before rake, just after rake and using -u and root with it.

My question is how do I make this command also prompt for the password when it tries to access the database, so it doesn't give me an error like this?

Community
  • 1
  • 1
Ahurasim
  • 27
  • 1
  • 8

2 Answers2

3

I would look at your config/database.yml file to ensure you have your DB username and password set correctly.

Edit:

I also found a useful link which helps not storing your password in the database.yml file as plain text, you store it as an ENV variable which can then be defined before accessing your database using the terminal.

instructions are here :

Securely providing the database password in a Rails app

wscourge
  • 10,657
  • 14
  • 59
  • 80
Mario Novello
  • 101
  • 1
  • 5
  • But im not looking to leave a password in plain text in that file id need to encrypt it somehow – Ahurasim Oct 20 '17 at 00:42
  • Have a look [here](https://stackoverflow.com/a/7306399/5786216) at this response to database.yml I'm not sure what you're asking is possible. Rails will use the database.yml file to connect to your DB on your different environments; it shouldn't be committed. – Mario Novello Oct 20 '17 at 00:50
  • 1
    @MarioNovello is correct, use `<%= ENV['YOUR_VAR_HERE'] %>` and set it in the server and don't commit it. In dev just use ur dev credentials. – Sean Oct 20 '17 at 02:49
  • Probably a newbie's question but what do you mean don't commit it? I understand what commit means just not what you mean by it? – Ahurasim Oct 20 '17 at 03:49
  • I did this so the password isnt stored as plain text in the yml file - https://stackoverflow.com/a/27430244/7124969 – Ahurasim Oct 20 '17 at 04:10
  • I would like to add that you want to configure this for each database environment you are using, development, testing, and production. You can read about this in more detail [here](https://kolosek.com/rake-db-commands/). – Nesha Zoric Mar 29 '18 at 14:13
0

Go to app/config/database.yml This file is responsible for databases connection configuration for various environment. ex. development, production etc.

ex.

 development:       

 adapter: mysql2

 encoding: utf8

 database:        #database name.

 username:        # mysql user name

 password:        # mysql Password

 host    :        # from where databases you asses from local or remote

                  remote you specify the remote server ip address.  

You need set password correctly.