A Simple Way to Reset MySQL/MariaDB root Password

Last Updated:

In this guide, we are going to learn a simple way to reset MySQL/MariaDB root password just in case you have lost, forgotten or just want to change it.

Resetting MySQL/MariaDB Root Password

To reset reset MySQL/MariaDB root password, step through the following;

NOTE: You must execute the following commands as root or with sudo privileges.

Stop MariaDB/MySQL Service

Login to the server hosting DB and stop DB service with either of the he following commands;

systemctl stop mariadb
systemctl stop mysql

Restart the Database in a safe mode

Start the database in safe mode using the command below;

mysqld_safe --skip-grant-tables --skip-networking &

This bypasses authentication processes and disable any connection to database. Hence you can login to database without password.

Login to Database

Login to database as root using either of the following commands;



mysql -u root

Reset MariaDB/MySQL root Password

Once you are logged in to database, run the command below to reload grant tables and reset root password.

update mysql.user set password=PASSWORD("StrongPASSW0rd") where user='root';

Reload grant tables and exit.


Stop the Database Service

Since the database service was launched to run in background in order to reset password, run the command below to safely stop it. This will prompt you to enter the new password set above.

mysqladmin -u root -p shutdown

Start the Database Service

Now that all is done, you can now start the database normally.

systemctl start mariadb

You have successfully reset MySQL/MariaDB root password and can now access the database with all administrative rights.


We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

Leave a Comment