Skip to Content

How to reset mysql or Mariadb root password ?

How to reset MySQL or MariaDB root password?

1.  First you need to stop MySQL or MariaDB server.

[email protected]:# service mariadb stop   

[email protected]:~#   service mysql stop   

 2. Start the MySQL/MariaDB server without loading the grant tables.

[email protected]:~# mysqld_safe --skip-grant-tables &

  When the --skip-grant-tables option is used, anyone can connect to the database server without a password and with all privileges granted. 

 3. Log in to the Mysql or MariaDB shell

[email protected]:~# mysql -u root

 4. Set a new password.

Type the following command, replacing "new-password"  with the new root password

MariaDB [(none)]> UPDATE mysql.user SET Password=PASSWORD('new-password') WHERE User='root';


MariaDB [(none)]> exit;

5. Stop the MySQL server using the following command. You will be prompted to enter the new MySQL root password before the MySQL server shuts down:

[email protected]:~# mysqladmin -u root -p shutdown

 6. Start the MySQL/MariaDB server normally

[email protected]:~# service mariadb start

7. Once started you can check the status of MariaDB service using service mariadb status command as shown below:

[email protected]:~#service mariadb status

8. Log in to MariaDB with New Password

Test the new reset MariaDB root password by logging in to the Server using mysql -u root -p command as shown below. Once you provide the root password it should allow you to log in just the way it is described below.

[[email protected] ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>