Databases 4 min read

How to Reset a Forgotten MySQL Root Password

This guide explains how to recover a lost MySQL root password by editing the MySQL configuration to skip grant tables, restarting the service, and then setting a new password via SQL commands, with platform-specific steps for Windows, macOS, and Linux.

Full-Stack Internet Architecture
Full-Stack Internet Architecture
Full-Stack Internet Architecture
How to Reset a Forgotten MySQL Root Password

1. Modify MySQL Configuration File

Open the MySQL configuration file: my.ini on Windows (located in the installation directory) or my.cnf on macOS/Linux (usually /etc/my.cnf). Add skip-grant-tables under the [mysqld] section to bypass authentication.

Note

If the configuration file does not exist on macOS, create /etc/my.cnf with the following content:

[client]
default-character-set=utf8
[mysqld]
bind-address = 127.0.0.1
character-set-server=utf8
skip-grant-tables

2. Restart MySQL

After saving the changes, restart the MySQL service so the new settings take effect.

Windows:

net stop mysql
net start mysql

Linux: service mysql restart macOS: restart via the graphical interface (as shown in the original screenshots).

3. Set a New Password

Once MySQL is running with skip-grant-tables, connect without a password: mysql -u root -p When prompted for a password, simply press Enter. Then execute the following SQL statements to set a new root password:

update user set password=password('new_password') where user='root';
flush privileges;
quit

Note

If you encounter the error

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

, first run flush privileges and then repeat the password‑setting commands.

Finally

After the new password is set, remove the skip-grant-tables line from the configuration file and restart MySQL again. The server will now require the new password for normal access.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ConfigurationLinuxmysqlWindowsmacOSDatabase Administrationpassword reset
Full-Stack Internet Architecture
Written by

Full-Stack Internet Architecture

Introducing full-stack Internet architecture technologies centered on Java

0 followers
Reader feedback

How this landed with the community

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.