HeresJohnny5 HeresJohnny5 - 1 month ago 13
MySQL Question

MySQL/Rails - Mysql2::Error (Access denied for user 'rails_user'@'localhost' to database 'simple_cms_development'):

I'm new to both MySQL and Rails. I'm going through a course on Lynda (Ruby on Rails 5) and I ran into a hiccup. After creating a database it's having me start up MySQL and Puma. I attempt to access localhost:3000 however I get the following error:

Mysql2::Error (Access denied for user 'rails_user'@'localhost' to database 'simple_cms_development'):


It seems like everything is working properly, both MySQL and Puma start:

Johns-MBP:simple_cms johnerickson$ mysql.server start
Starting MySQL
SUCCESS!
Johns-MBP:simple_cms johnerickson$ rails s
=> Booting Puma
=> Rails 5.0.0.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.6.0 (ruby 2.3.0-p0), codename: Sleepy Sunday Serenity
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
* List item


Below is my database.yml file:

default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: rails_user
password: ***The password works***
host: localhost

development:
<<: *default
database: simple_cms_development


I looked through Stack Overflow and see others have had similar issues, however it seemed to be a password issue, which I'm not having. Any help will be greatly appreciated.

Answer

This particular user does not have enough rights to access the DB. Try after running following commands in mysql prompt. You may have to log as root or some other admin user in order to run this.

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