Access denied for user 'root'@'localhost'

Solution 1:

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)

Solution 2:

The problem was the permissions granted to root in the information.schema table. 'root'@'%' didnt have any permissions.. And as I was using 127.0.0.1 as my connection address, so it was giving the access denied error.. % is the wildcard for an ip address. so mysql considers [email protected] as any other ip address but not localhost. so just granting it permission solved my problem.. Try using some Mysql client like SQLYog etc.. it is easy to grant the privileges and also to view the privileges with the user.