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.

  • Examine the source sql file you ran. Did it contain anything like a mysql.users table or any GRANT, set password or create user queries? It's possible you blew out your root account credentials with that. – atxdba Jan 13 '15 at 0:41
  • ya, it has mysql.users table or GRANT. It may be the reason. What if I delete that particular database? Does it work? – gimibarak Jan 13 '15 at 0:45
  • See the link in my answer below on how to restore – atxdba Jan 13 '15 at 0:51

If you have access to restart the mysql daemon you can follow the mysql directions for recovering your root account.

| improve this answer | |
  • I didn't find any of these directories /var/lib/mysql/ /var/run/mysqld/ and /usr/local/mysql/data/ in my server. – gimibarak Jan 13 '15 at 1:03
  • Do a search for the mysqld programme from the root (you need the machine root password) - sudo find . -name "mysqld". – Vérace Jan 13 '15 at 1:13
  • No I tried using the command, but no result. – gimibarak Jan 13 '15 at 4:53
  • Find the mysqld in your processlist. Run sudo lsof -p PID where PID is the process id of your mysqld process. This should show you file handles it has open – atxdba Jan 13 '15 at 18:16
  • @atxdba I didn't find the file with name mysqld in the processlist. Do you have any idea, usually where it will be?? – gimibarak Jan 15 '15 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.