I am not able to login into phpmyadmin. It shows the following error.

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

I tried to login to run mysql -u root -p, but it also shows the same error.


Follow the steps below.

  1. Start the MySQL server instance or daemon with the --skip-grant-tables option (security setting).

    $ mysqld --skip-grant-tables
  2. Execute these statements on new terminal.

    $ mysql -u root mysql
    $mysql> UPDATE user SET Password=PASSWORD('my_password') where USER='root';

If you face the unknown field Password error above use:

update user set authentication_string=password('my_password') where user='root';
  1. Finally, restart the instance/daemon without the --skip-grant-tables option.

    $ /etc/init.d/mysql restart

You should now be able to connect with your new password.

$ mysql -u root -p

Enter password: my_password

  • mysql -u root is also showing the same error. – Ajay Pandita Apr 25 '16 at 12:55
  • @AjayPandita : I have updated my answer, please follow the procedure and check. – Rahul Apr 25 '16 at 13:34
  • Your answer might not work in some cases. Different MySQL versions and setups use a different field other than password. @AjayPandita if you're still having trouble, follow the directions at dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html – Otheus Apr 25 '16 at 14:04
  • Also, by not specifying the host as localhost, your answer possibly overwrites all root login's passwords. In this user's case that's probably OK. But not for other users with a similar problem. – Otheus Apr 25 '16 at 14:09

MySQL authentication is a 'many splendored thing', or FUBAR depending on how you look at it. Different versions and setups can use different authentication methods. Arzyfex's advice might not work all the time. The best advice is to follow the MySQL manual here: http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html. To handle the various different authentication formats, mysql wants you to use set password for root, but this command will not work when --skip-grant-tables option is used at server startup! So the prescribed formula is to start the mysql server with a special init-file which contains the set password command.

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.