I want to access the MariaDB database using the root user, but I forgot the password of the root user.
Problem
How to reset MariaDB root password?
Solution
When I insert my password root to access MariaDB, here is the error:

Here are the steps to reset the root password in MariaDB:
1. Stop the service
Use the command below to stop MariaDB’s service:
sudo systemctl stop mariadb
2. Running Mariadb in Safe Mode
Run the command below to run the MariaDB service without access rights and networks:
sudo mysqld_safe --skip-grant-tables --skip-networking &
3. Change the password
Enter MariaDB using the command:
sudo mariadb -uroot -p
Press the Enter button and after that, type the commands below, and I use the qwerty password as my new password:
FLUSH PRIVILEGES;
ALTER USER root@localhost IDENTIFIED BY 'qwerty';
FLUSH PRIVILEGES;
exit
4. Stop MariaDB
Use the command below to stop MariaDB’s service:
sudo mysqladmin -u root -p shutdown
Enter the password you just created if you are asked to enter a password.
5. Running the Service
Run the command below to turn on MariaDB’s service:
sudo systemctl start mariadb
6. Try a new password
Enter MariaDB by using the password that you created previously using the command below:
sudo mariadb -u root -p
Insert your new password, and if you type the correct password, then you should be able to enter Mariadb as in the image below:

Note
Maybe as an alternative to storing passwords for the root user in MariaDB, you can store the password in a file, but using an encrypted Vim editor.
References
musaamin.web.id
serverspace.io
vexxhost.com
stackoverflow.com

