Reset MariaDB root password on linux

An easy way to reset the password of the root user on linux.

SNP 007 #139 Filed cmd

At first you need to stop the service.

shell
sudo systemctl stop mariadb

Then you need to restart the service without permission checking.

shell
sudo mysqld_safe --skip-grant-tables --skip-networking &

Note the returned process ID.

Then we can log in without a password.

shell
mysql -u root

Load up the grant tables with:

shell
FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

Then set the new password.

shell
ALTER USER 'root'@'localhost' IDENTIFIED BY 'cool_password';
Query OK, 0 rows affected (0.01 sec)

Exit the MariaDB with:

shell
exit;

Now kill the process you started in the background. Use the process ID you noted earlier instead of 1234.

shell
sudo kill -9 1234

Then start up MariaDB and check if you can log in with your cool new password.

shell
sudo systemctl start mariadb
mysql -u root -p