Simple Steps How to Reset Password on MySQL/MariaDB (username root)

How To Reset Password On Mysql Or Mariadb

Password is something important to login. Hence, it should be remembered to protect the safety of your data. However, forgetting passwords seems to be happening to a lot of us, especially to MySQL and MariaDB. You need to know how to reset PW MySQL/MariaDB (username root).

That’s the only way to get back to the platform and access the account. There are steps that you’ll need to access your mySQL or MariaDB again. The tutorial below will show you how it’s done properly even though your username has been rooted before.

Steps How to Reset PW MySQL/MariaDB (username root)

1. Know your database version

This is the most important step before you’re doing other steps after. If you’re using modern or the latest Linux,it will be easier since it’s always compatible with MySQL. However, the Linux version must be known because the issue might be slightly different for rooted username.

  • The command you need to submit:
mysql –version

The result for MySQL and MariaDB will give you different versions with similar lines. The output will show you which version, the distrib, and wrapper. The example:

  • MySQL: mysql  Ver 14.14 Distrib 5.7.16, for Linux (x86_64) using  EditLine wrapper
  • MariaDB: mysql  Ver 15.1 Distrib 5.5.52-MariaDB, for Linux (x86_64) using readline 5.1

After that, you have to take note of the version in other place. You will type it down later and then close the command. For the next one, you’ll access manually.

2. Stop the database server

This step is simple. The command you’ll input will be different for mySQL and MariaDB. Once the input is submitted, the database server will be automatically stopped.

  • MySQL:
sudo systemctl stop mysql
  • MariaDB:
sudo systemctl stop mariadb

3.       Restart the database

The next step of how to reset PW MySQL/MariaDB (username root) is by restarting the database. This work might be a bit risky. To prevent any mistake, you have to cut off the network with other clients before you input several commands below.

Take the note that running to restart the database might take forever. Just in case it happens instantly, it’s gonna be a privilege. However, the command for rooted username is a rare case to get fast loading information.

sudo mysqld_safe --skip-grant-tables --skip-networking &
mysql -u root

After that, input different prompts for MySQL and MariaDB below:

  • MySQL: Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement. mysql>
  • MariaDB: Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement. MariaDB [(none)]>

4. Changing the password

The next step for how to reset PW MySQL/MariaDB (username root) command is changing the password by inputting the commands below:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');

Input your new password after that and make sure you’re replacing new_password

Query OK, 0 rows affected (0.00 sec),

If the last command has been shown, it means that the password has been changed successfully.

5. Restart the database

Don’t forget to restart the database. Use the commands below:

  • MySQL:
sudo systemctl start mysql
  • MariaDB:
sudo systemctl start mariadb

After that, the newest password has been applied.

The steps on how to reset PW MySQL/MariaDB (username root) might be complicated, but it’s worth a try. Your MyQSL and MariaDB might be important as the data is all there. Make sure the ON and OFF server are done carefully.