MySQL Error: 'Access denied for user 'root'@'localhost'

Dung Do Tien Jun 29 2021 306

I have a project using Php 7 and MySql and deploy in Ubuntu 20.04. I just installed MySql successful but when I run the command:

 $ ./mysqladmin -u root -p 'redacted'

I get an error:

mysqladmin: connect to server at 'localhost' failed error:
'Access denied for user 'root'@'localhost' (using password: YES)'

How can I fix it?

Have 2 answer(s) found.
  • M

    Minh Yến Jun 29 2021

    You can resolve your issue by following some steps below:

    1. Open & Edit /etc/my.cnf or /etc/mysql/my.cnf, depending on your distro.
    2. Add skip-grant-tables under [mysqld]
    3. Restart Mysql
    4. You should be able to login to mysql now using the below command mysql -u root -p
    5. Run mysql> flush privileges;
    6. Set new password by ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
    7. Go back to /etc/my.cnf and remove/comment skip-grant-tables
    8. Restart Mysql
    9. Now you will be able to login with the new password mysql -u root -p

     I hope it works for you!

  • M

    Mary Christ Jun 29 2021

    Maybe You have to reset your root password. Have in mind that it is not advisable to use root without a password.

    To reset the password for MySql you can refer to this article https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close