Skip to content

Resetting the MySQL root password

This guide explains how to reset the MySQL root password, for example, if you have forgotten it.

Note: You must have root access on the server to perform these steps.

  1. Log in via SSH to your server.

Note: Run the following commands as the root user. You can either log in directly as root (not recommended for security reasons) or use su / sudo.

  1. Stop the MySQL server:
service mysqld stop
service mysql stop
  1. Restart MySQL with grant tables disabled:
mysqld_safe --skip-grant-tables &

Important: The & runs the command in the background, allowing you to continue typing commands.
Running MySQL this way is highly insecure—only do this briefly to reset the password.

  1. Log into MySQL:
mysql
  1. Reset the root password:
UPDATE mysql.user SET Password=PASSWORD('new-password') WHERE User='root';

Replace 'new-password' with your desired root password.

  1. Apply changes and exit:
FLUSH PRIVILEGES;
exit;
  1. Stop MySQL safely:
mysqladmin -u root -p shutdown
  • Enter the new root password when prompted.
  1. Start MySQL normally:
service mysqld start
service mysql start

Your MySQL root password is now successfully reset.