Friday 25 May 2018

How to Reset MySQL root Password in Linux


How to Reset MySQL root Password in Linux
How to reset MySQL root password in Linux? How do I recover MySQL root password? I forgot MySQL root password, steps to change MySQL root password? How to reset MySQL root password using the command line. How to reset forgotten MySQL root password on Linux? How to reset MySQL 5.7 root password? 
 
MySQL is an open source database software widely used for data storage. Sometimes we forgot MySQL root password. So don’t be panic, This tutorial will help you to reset MySQL root password with simple steps.
Step 1 – Start MySQL in Safemode
First of all, you are required to stop running MySQL server. Use one of the following commands to stop MySQL server on your Linux system.
# service mysql stop             
# systemctl stop mysql.service   
Now start MySQL server in safe mode using withe the --skip-grant-tables option. Use the following command to start MySQL in safe mode. In safe mode, MySQL does not prompt for login password.
# mysqld_safe --skip-grant-tables &
Step 2 – Reset MySQL root Password
Now login to MySQL server as root user and change password using the following set of commands. This will reset MySQL root password on your system.
For MySQL 5.6 or Below
# mysql -u root

mysql> USE mysql;
mysql> UPDATE user SET password=PASSWORD("NEW-PASSWORD") WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
For MySQL 5.7 or Above
# mysql -u root

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD("NEW-PASSWORD");
mysql> FLUSH PRIVILEGES;
mysql> quit
Step 3 – Restart MySQL Server
After changing password stop the MySQL (running in safe mode) service and start it again with the commands below.

# service mysql stop
# service mysql start


# systemctl stop mysql.service
# systemctl start mysql.service
Step 4 – Verify New Password
After resetting MySQL root account password and restarting, just verify new password by login.
# mysql -u root -p

Enter password: **********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 29
Server version: 5.5.57 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

No comments: