Follow us on Social Media:

MySQL Database Administrator

Boost Your Quick Knowledge in MySQL DBA Work, Concepts, Tips and Trick

Wednesday, 21 March 2018

How to reset MySQL root password in Linux ?

Reset MySQL Root Password: Linux Systems


In this article, I am discussing about how to reset MySQL Root password for 'root'@'localhost' once you forget or lost.

You must have root access on the server to reset the MySQL root password.

To change the password for a root account with a different host name part, modify the instructions to use that host name.

1.    Log in to your account using SSH.
You must run the commands in the following steps as the root user. Therefore, you can either log in directly as the root user (which is not recommended for security reasons), or use the su or sudo commands to run the commands as the root user.

2.    Stop MySQL service.
1: For CentOS
           service mysqld stop
2: For Debian and Ubuntu
           service mysql stop

3.      Restart MySQL server with the –skip-grant-tables option.

mysqld_safe –skip-grant-tables &
·       Must add & (ampersand) at end of above command. This runs the command in the background and allows you to type the commands in the following steps
·       Running MySQL with the —skip-grant-tables option enabled is highly insecure, we request you please perform this task in minimum time period. The steps below show you how to stop the mysqld_safe server instance safely and start the MySQL server securely after you have reset the root password.


4.   Log into MySQL using the following command:
mysql

5.  At the mysql> prompt, reset the password. To do this, type the following command, replacing NEW-PASSWORD with the new root password:
Update mysql.user set password=‘GetMySQL’ where user=’root’;

6.    At the mysql> prompt, type the following commands:
FLUSH PRIVILEGES;
Exit;

7.    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:
mysqladmin –u root –p shutdown

8.   Start the MySQL server normally. To do this, type the appropriate command for your Linux distribution:
1: For CentOS and Fedora type:
           service mysqld start
2: For Debian and Ubuntu:
           service mysql start

No comments:

Please Like and Subscribe us ....

Please visit the website on daily basis , Your New articles will publish at any moment. Please Subscribe us for getting Latest Updates...