How Reset root password in MySQL and MariaDB

If you assigned a root password in MySQL or MariaDB previously but have forgotten it, you can assign a new password. The following sections provide generic instructions for that apply to any system. On any platform, you can reset the password using the mysql client (but this approach is less secure):

  • Stop the MySQL or MariaDB server


  • Then restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges, and disables account-management statements such as ALTER USER and SET PASSWORD. Because this is insecure, you might want to use --skip-grant-tables in conjunction with --skip-networking to prevent remote clients from connecting.


  • Connect to the MySQL or MariaDB server using the mysql client. No password is necessary because the server was started with --skip-grant-tables:


  • In the mysql client, tell the server to reload the grant tables so that account-management statements work:


  • Then change the 'root'@'localhost' account password. Replace the password with the password that you want to use. To change the password for a root account with a different host name part, modify the instructions to use that host name.

MySQL 5.7.6 and later:

MySQL 5.7.5 and earlier:


  • You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally (without the --skip-grant-tables and --skip-networking options).


If the ALTER USER statement fails to reset the password, try repeating the procedure using the following statements to modify the user table directly:




Related Topic:

MySQL: Run Query from Bash Script or Linux Command Line

How Create MySQL Database with User and User Privileges

MySQL: Show Users, Privileges and Passwords



Pin It on Pinterest