Mysql2::Error: Access denied for user 'rails_user'@'localhost' (using password:YES)

1.7k views Asked by At

I am trying to create a database and connect it with my rails app.

When I try to check if my database are properly connected via:

rails db:schema:dump

It gives me the ff error:

Mysql2::Error: Access denied for user 'rails_user'@'localhost' (using password:
YES)
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:schema:dump
(See full trace by running task with --trace)

This blows my mind as did used the exact password when I created the DB:

default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: rails_user
  password: grace0512
  host: localhost

development:
  <<: *default
  database: test_project_development

# 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: test_project_test

I did try this:

grant all on simple_cms_development.* to 'rails_user'@'localhost' identified by '<password>';
flush privileges;

But did not solve my issue. Any help please?

I really need to solve this to move forward!

2

There are 2 answers

0
Jessica Wallace On

Have you fixed it yet?

I changed it slightly and put

    GRANT ALL PRIVILEGES ON demo_project_development.* to rails_user@localhost IDENTIFIED BY 'password';
    FLUSH PRIVILEGES; 

Although I still received Rails warnings, it successfully did a schema dump afterwards!

0
chandraprakash-dev On

The SQL command you need to run is:

GRANT ALL PRIVILEGES ON test_project_development.* to 'railsuser'@'localhost' 
IDENTIFIED BY 'grace0512';

Please also run this command immediately after to be consistent:

GRANT ALL PRIVILEGES ON test_project_test.* to 'railsuser'@'localhost' 
IDENTIFIED BY 'grace0512';

There is no need to use flush privileges as MySql automatically reloads the grant tables.

If that did not work, did you run bundle install on command line in your project root after you updated database.yml? if so, recheck if you mispelled the username or password.