How to Change or Reset MySQL Root Password via Command Line
How to access MySQL Command line or shell?
If MySQL server already installed on your server, then you can access it through shell or command line.
First, login to the server as a root and then enter below command to access MySQL shell interface.
You can use any of the below Commands to access MySQL command line.
mysql
mysql -u root -p
In the above command u flag indicates root user, and -p flag for password authentication.
You have to enter password to access MySQL.
mysql>
Now, you are ready to reset default password for MySQL user.
How to Change or Reset MySQL root Password?
The MySQL database server users, databases, permissions and configuration data will be stored in default mysql database.
You need to select the mysql database through below command to set new password.
To make a database "mysql" the current database, execute this below query:
mysql> use mysql;
The above command gives you following output and shows that database has changed.
mysql> use mysql;Database changed
Next, you need to update MySQL root user password with below query.
mysql> update user set password=PASSWORD('new_password') where User='root';
In the above query, the "new_password" represents your new password. Replace it with whatever your choice but make sure to use high strength password.
Finally, reload the privileges of MySQL server using below command.
mysql> flush privileges;
Now that MySQL root password has changed to desired one, you can exit MySQL command line.
mysql> exit;
Tip: The above instructions works for changing or resetting password for any MySQL user. You just need to replace user root with another.
Post a Comment