Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

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.

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.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

ConfigurationLinuxMySQLWindowsmacOSDatabase Administrationpassword reset

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion