There is no one in this world that hasn’t forget a password in his entire life, whether it is of Instagram, Gmail, or even a normal e-commerce website. However, resetting them is not a hard task at all. This tutorial will guide you on how to reset the MySQL root password. Learn about MySQL. So that, you have no worries about remembering the password as you can reset it easily.
Pre-requisites
You must have root access on the server to reset the MySQL root password.
MySQL root password gives full access to MySQL database to the root user. You must have Linux root or Windows Administrator access to the Cloud server to reset the MySQL root password. You can also learn to install Java 9 on Linux.
Here are the steps you can follow to reset a MySQL root password via the command line.
Resetting the MySQL root password
- Firstly we need to stop the MySQL service. If using CentOS/RHEL or Fedora, execute the following command:
sudo service mysqld stop
Ubuntu or Debian users can execute the following command:
sudo service mysql stop
- Now after the server being stopped, restart the MySQL server with the —skip-grant-tables option. To do this, run the following command on your terminal:
mysqld_safe --skip-grant-tables &
( ‘–skip-grant-tables’ is not recommended and should only be used in case you need to change your password. )
- Connect to MySQL by the following command :
mysql -uroot
- After successfully connecting, set a new MySQL root password. This can be done by executing the following command :
Here, we are using “ User=’root’ ” to change the root user account password but we can also reset the password for another account by replacing ‘root’ with that user account.
UPDATE mysql.user SET Password=PASSWORD('updated-password') WHERE User='root';
- At the mysql> prompt, execute the following commands:
FLUSH PRIVILEGES;
exit;
- Stop MySQL by running the following command. Before the MySQL server is shut down, you will be requested to enter the new root password.
Ubuntu or Debian user run the following command:
sudo service mysql restart
For CentOS/RHEL or Fedora users:
service mysqld restart
- You can verify if the password has been reset or not by simply logging in to the database.
mysql -u root -p
- Enter your new password when prompted. This is it. Isn’t it easy!!!!
Also Check: How to Install ADB and Fastboot on Ubuntu, Debian, Linux Mint
Wrapping Up
This tutorial explored different methods to reset the MySQL root password. If you encounter any issues, share them in the comments section, and I would be more than happy to assist you.