Databases 3 min read

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.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
How to Reset a MySQL Root Password When Access Is Denied

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 -p

2. Switch to the mysql database and change the root password:

use mysql;
update user set password=PASSWORD("newpass") where user="root";
flush privileges;
quit

3. Restart MySQL and log in with the new password:

# service mysqld restart
# mysql -uroot -pnewpass

Problem 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.

DatabaseMySQLTroubleshootingresetroot-passwordskip-grant-tables
Practical DevOps Architecture
Written by

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.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.