How do you reset a forgotten MySQL root password?

BeginnerHands-onMySQL
Answer

Short answer

Stop MySQL, start it without permission checks (--skip-grant-tables, no networking), log in without a password, set a new root password, then restart MySQL normally.

Steps (MySQL 8 on Linux)

sudo systemctl stop mysql
sudo mysqld_safe --skip-grant-tables --skip-networking &      # nobody can connect remotely meanwhile
mysql -u root
FLUSH PRIVILEGES;                                  -- load the grant tables so ALTER USER works
ALTER USER 'root'@'localhost' IDENTIFIED BY 'N3w-Str0ng-Pass!';
EXIT;
sudo pkill mysqld
sudo systemctl start mysql
mysql -u root -p

On Ubuntu with auth_socket

Root often logs in through the OS (sudo mysql) with no password at all — try that first.

Docker

Start a temporary container with the same volume and --skip-grant-tables, or recreate with MYSQL_ROOT_PASSWORD (only applies to a fresh, empty data directory).

Managed databases

RDS/Azure: reset the master password from the console/CLI — you can't do the steps above.

What to say in the interview

"Stop the service, start mysqld with skip-grant-tables and skip-networking, flush privileges, ALTER USER root with a new password, then restart normally. On RDS you reset the master password through the API instead."

All Databases (MySQL, PostgreSQL, MongoDB) questions Roadmap: MySQL basics

More on MySQL