A customer needed help with their database for their website today, the developer had forgotten the root pass of the database holding all of their information, so of course we had to help out!
Start by stopping the service
systemctl stop mariadb
Now we set a flag for it to start with, on next start up
sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
Start it
systemctl start mariadb
Now check that the flag we set actually took
sudo systemctl status mariadb

Now you should be able to login to the database without a password
mysql -u root
Now to set the new root password, just follow along and set your new password in the ‘YourNerPasswordHere’ box 😀
USE mysql;
UPDATE user SET password=PASSWORD('YourNewPasswordHere') WHERE User='root' AND Host = 'localhost';
FLUSH PRIVILEGES;
exit
Thats it you have set a new password for ‘root’
Now lets stop the service again, unset the environment variable and kickstart the database with a brand new root password.
systemctl stop mariadb
sudo systemctl unset-environment MYSQLD_OPTS
systemctl start mariadb
Now the service is running and your root account have a brand spanking new password.
Happy trails my fellow IT nerds