ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) I know this might be a duplicate of some other posts. But those solutions didn't work for me and I've lot of issues within those answers. Neither could I comment nor post in there, I'm posting a question.

In my case, I logged into mysql as 'root' and tried to import a sql file into the database. I then exited, did nothing and when again tried to login with the same user. But this time it was showing as 

bash-2.05$ mysql -u root -p                 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)


And I tried all different solutions(suggestions from other posts) like mysql -u root -ppwd -h127.0.0.1 mysql -u root -ppwd --protocol=TCP. These suggestions didn't work for me. I couldn't login as the root and without that I will not be having permissions to change any privileges. I'm sure user and password are the correct ones. 

Apart from all this, I'm using this database for a drupal website. The website gives me an error as 

PDOException: SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: YES) in lock_may_be_available() (line 167 of /home/apache2/htdocs/website/includes/lock.inc).


I couldn't trace what's going wrong with this.
If you have access to restart the mysql daemon you can follow the mysql directions for recovering your root account.