Saucepan

How to guides and technology tutorials for Amazon AWS, Google Cloud, Linux, macOS, Windows, and other systems

How to reset root password on MariaDB or MySQL on CentOS

Published: 06 March 2017
Filed Under: CentOS

What if you forget the root password to MariaDB or MySQL? You can reset the password following this easy tutorial.

Stop MariaDB and start it with privileges

Run the following commands to stop the MariaDB service and start it with special privileges that won't require you to enter a password.

sudo systemctl stop mariadb
sudo mysqld_safe --skip-grant-tables &

Change the password

Reset the password using the following commands. Be sure to replace PASSWORDHERE with the new password you want.

mysql -u root
use mysql;
update user SET PASSWORD=PASSWORD("PASSWORDHERE") WHERE USER='root';
flush privileges;
exit

Restart MariaDB

Start the normal MariaDB service.

sudo systemctl start mariadb