Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

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

$ ./mysqladmin -u root -p 'redacted'
Enter password:
mysqladmin: connect to server at 'localhost' failed error:
'Access denied for user 'root'@'localhost' (using password: YES)'

How to fix this issue?

2 Answers

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
In case your error is-
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Then, it can be solved by the following code-
sudo mysql -u root -p mysql
You do not have to restart MySQL, instead, use the following-
sudo mysql
-- for MySQL
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
-- for MariaDB
ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('root');

In this case, we are changing the auth_plugin to mysql_native_password with only a single query. And we are setting the password to root.

Login / Signup to Answer the Question.