How to Reset MySQL root Password in Linux
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 //For SysVinit based ystems
# systemctl stop mysql.service //For Systemd based Systems
Now, start MySQL server in safe mode using the following command:
# mysqld_safe --skip-grant-tables &
In safe mode, MySQL does not prompt for login password.
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:
//For SysVinit based systems
# service mysql stop
# service mysql start
//For Systemd based systems
# 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 logging in.
[color=black][color=brown][size=14pt]# 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 na# 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>mes may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>[/size][/color][/color]