Today, In this article we are going to learn how to “Reset MySQL Root Password“.
It is a good option to use this method only for resetting the password but it is highly insecure. So make sure after resetting the password, you also revert the changes from my.cnf file.
Note:
For Centos and Fedora Based OS
sudo service mysqld stop
sudo service mysqld start
For Debian and Ubuntu OS
sudo service mysql stop
sudo service mysql start
Steps
Here i am using amazon linux 2 OS (based on centos)
- Stop mysql service – sudo service mysqld stop
- Open /etc/my.cnf file – sudo nano /etc/my.cnf
- Add skip-grant-tables under [mysqld] section
- Start MySql Service – sudo service mysqld start
- Open terminal and type mysql
- and type following query and press enter
UPDATE mysql.user SET authentication_string=PASSWORD(‘Your new password’) WHERE User=’root’; - Then write FLUSH PRIVILEGES; and press enter
- Now type – exit;
- Stop mysql service again – sudo service mysqld stop
- Open my.cnf file – sudo nano /etc/my.cnf
- Remove skip-grant-tables and save the file.
- Now Start the mysql – sudo service mysql start
- Great!!! You have successfully reset your MySQL root password.
Now you can login as a root user with your new password. To do this Open terminal and type
mysql -u root -p and press enter and type your new password to login.
Also checkout my other mysql tutorial
If you have any questions related to this article. Please leave it in comments.
And if you liked this article then please do like and share this post.
Thanks for reading 🙂 🙂
Comments
Post a Comment