How to Reset a MySQL Root Password When Access Is Denied
This guide explains step‑by‑step how to recover a lost MySQL root password by stopping MySQL, starting it with skip‑grant‑tables, updating the password in the mysql.user table, flushing privileges, and then restarting the service for normal operation.
Problem 1: MySQL login error When attempting to connect as root you may see: mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: YES)'
Solution: Reset the MySQL password
1. Stop the MySQL service and start it without privilege checking:
# service mysqld stop
# mysqld_safe --skip-grant-tables &
# mysql -uroot -p2. Switch to the mysql database and change the root password:
use mysql;
update user set password=PASSWORD("newpass") where user="root";
flush privileges;
quit3. Restart MySQL and log in with the new password:
# service mysqld restart
# mysql -uroot -pnewpassProblem 2: Forgotten local root password
Steps to recover:
Edit /etc/my.cnf and add skip-grant-tables under the [mysqld] section.
Save the file and restart MySQL: # service mysqld restart
Log in without a password and reset the root password: # mysql -uroot -p mysql> update user set password=password("mysql") where user='root'; mysql> flush privileges;
Remove the skip-grant-tables line from /etc/my.cnf and restart MySQL again.
After these steps you can log in normally with the newly set password.
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.