reset mariadb root password
Posted on in linuxLast edited on
Some few days ago I repeated one of the more common ‘mistakes’ I find myself making every once in a while: I setup a vm to test something out, install mariadb, set a root password and then immediately forget it.
What follows is usually me searching for the notes I made only to find out that there are none. 😅
So here’s my notes on resetting the root password on mariadb, so that I don’t have to search for them and maybe remember them in the future:
| ⚠️ This has last been tested with Mariadb 10.5 |
|---|
Necessary steps
- Stop the mariadb service
systemctl stop mariadb.service - Start mariadb in safe mode without networking:
mysqld_safe --skip-grant-tables --skip-networking & - Login to the service:
mysql - Reset the password:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newrootpassword'); - Flush privileges:
FLUSH PRIVILEGES - Logout from service:
quit - Stop mariadb:
mysqladmin -uroot -p shutdown
For later versions this should still work, because from what I recall, mysqld_safe is already a symlink to mariadbd-safe for compatibility reasons. It takes some command line arguments and forwards the rest to mysqld, which also is a symlink to mariadbd. And last but not least, mysqladmin is a symlink to mariadb-admin.
I believe you could as well call these directly, but I have yet to test this.
Bonus
If you want to make sure that the password actually changed, you can run the following query before and after step 4 :
SELECT * FROM mysql.global_priv WHERE User = 'root';