MySQL Error: 'Access denied for user 'root'@'localhost'
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?
-
M0
Minh Yến Jun 29 2021
You can resolve your issue by following some steps below:
- Open & Edit
/etc/my.cnf
or/etc/mysql/my.cnf
, depending on your distro. - Add
skip-grant-tables
under[mysqld]
- Restart Mysql
- You should be able to login to mysql now using the below command
mysql -u root -p
- Run
mysql> flush privileges;
- Set new password by
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
- Go back to /etc/my.cnf and remove/comment skip-grant-tables
- Restart Mysql
- Now you will be able to login with the new password
mysql -u root -p
I hope it works for you!
- Open & Edit
-
M0
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
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.