How to reset MySQL / MariaDB Root Password

  • 01 February 2017
  • ADM

 

How to reset MySQL / MariaDB Root Password - images/logos/mysql.jpg

 

This article will show how to reset the root password for MySQL / MariaDB.

Step 1 - Stop the service

$ sudo systemctl stop mariadb.service

Step 2 - Start the service without password

$ sudo mysqld_safe --skip-grant-tables &

Step 3 - Connect to MySQL/MariaDB with root user

$ mysql -u root

Step 4 - Update the password

Use the following commands to reset root's password. Replace password with a strong password:

USE mysql;
UPDATE user SET PASSWORD=PASSWORD("password") WHERE USER='root';
flush privileges;
exit;

Step 5 - Restart the service

$sudo systemctl restart mariadb.service

Step 6 - Test the change

Login to the DB using the new password.

$ mysql -u root -p