Recovery Password MariaDB Database
In this tutorial, I will explain the solution when you forget the root password of the MariaDB database. This method cannot be used for the MySQL database, even though hierarchically, MariaDB is derived from upstream MySQL.
Note: Some of the steps below are very interrelated, so you must follow all the steps below:
- Stop the MariaDB service.
systemctl stop mysql.service - Check the service to ensure it is inactive.
systemctl status mysql.service - Run the MySQL Safe Mode Command
mysqld_safe --skip-grant-tables --skip-networking & - Log in to the MySQL Console as usual without the -p parameter.
mysql -u root - Reset the MySQL root password In the MySQL Console
mysql >Change the password with the following command:
UPDATE mysql.user SET Password=PASSWORD('NEW-PASSWORD') WHERE User='root'; - Flush existing privileges In the MySQL Console
mysql>
FLUSH PRIVILEGES;
exit; - After finishing with MySQL Safe Mode, stop the MySQL Safe Mode process.
kill cat /var/run/mysqld/mysqld.pid - Start the MySQL service as usual.
systemctl start mysql.service - Check the MySQL Service
systemctl status mysql.service
Once completed, you can log in to the MySQL database with the root password that was changed earlier. - Log in to the MySQL Database.
mysql -u root -p
Enter the MySQL password that was changed previously.