Access denied for user ‘root’@’localhost’

Start mysql client in the console and execute this query: select Host, User from mysql.user;. You MUST have a row like this:

+----------------+------------------+  
| Host           | User             |  
+----------------+------------------+  
| localhost      | root             |
+----------------+------------------+  

a row with “localhost” in Host and “root” in User. If you don’t have it that’s the cause of your problem (it doesn’t matter if you have other rows with “root” in User)

If you don’t have such row, add a new user with this:

CREATE USER 'appUser'@'localhost' IDENTIFIED BY 'appPassword';

Change ‘appUser’ by ‘root’ if you want, but I strongly suggest to use another user. Then add permissions to your new user by executing this in the mysql client:

GRANT ALL PRIVILEGES ON employees.* TO 'appUser'@'localhost';

(again, change ‘appUser’ by ‘root’ if you want)

Leave a Comment