Knowing the MySQL/MariaDB root password of your server can come in handy in several cases such as accessing the database server console to manually create databases, create users and associate them with the databases, grant privileges to database users on specific databases etc.
If you are unsure of the MySQL/MariaDB root user password, then the below steps will guide on how to reset the root password safely. Resetting/changing the database server root password occasionally is also an important security factor, which helps protect against unauthorized intrusion attempts.
The below steps can be followed to reset root password for MySQL & MariaDB respectively.
Stop MySQL service using below command.
# systemctl stop mysqld
Restart MySQL server in safe mode by executing below commands.