How to set a mysql password for root

Did you forget your root password for mariadb or mysql?

Are you on plesk?
Show the password:
cat /etc/psa/.psa.shadow
In plesk 8 and up, the password is encrypted.
You can still get it with this command:
/usr/local/psa/bin/admin –show-password

And this will help you to login to root mysql without knowing your plesk version or password:
MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin

Once you’re logged in, you can change the root password if you like…
SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘MyNewPass’);