Stack Engineer

Reset Root Password on MariaDB or MySQL

What if you forget the root password to MariaDB or MySQL? You can reset the password following this easy tutorial.

Step 1 - Stop MariaDB and Start it With Privileges

Run the following commands to stop the MariaDB service and start it with special privileges that won't require you to enter a password.

sudo systemctl stop mariadb
sudo mysqld_safe --skip-grant-tables &

Step 2 - Change the Password

Reset the password using the following commands. Be sure to replace PASSWORDHERE with the new password you want.

mysql -u root
use mysql;
update user SET PASSWORD=PASSWORD("PASSWORDHERE") WHERE USER='root';
flush privileges;
exit

Step 3 - Restart MariaDB

Start the normal MariaDB service.

sudo systemctl start mariadb