How to reset root password on MariaDB or MySQL on CentOS
Published: 06 March 2017
Filed Under: CentOS
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
Start the normal MariaDB service.
sudo systemctl start mariadb