How to restore mysql root password on Linux when you forget password? This task will be very simple if you follow the steps in this article.
Step 1 : Stop MySQL Server Service
You run this command to stop MySQL Server on linux
service mysqld stop
Step 2 : Restart MySQL Server without password
mysqld_safe –skip-grant-tables &
After you run the command above, you enter to continue running other commands
[root@server ~]# 180531 10:57:35 mysqld_safe Logging to ‘/var/log/mysqld.log’.
180531 10:57:35 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Step 3 : Connect MySQL Server via MySQL client
mysql -u root
[root@server ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distributionCopyright (c) 2000, 2013, 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>
Step 4: Set new password MySQL Server for user root
USE mysql;
UPDATE user set password=PASSWORD(“NEW-ROOT-PASSWORD”) WHERE User=”root”;
flush privileges;
quit
mysql> USE mysql;
No connection. Trying to reconnect…
Connection id: 3
Current database: *** NONE ***Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> UPDATE user set password=PASSWORD(“NEW-ROOT-PASSWORD”) WHERE User=”root”;
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3 Changed: 3 Warnings: 0mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)mysql> quit
Bye
[root@server ~]#
Step 5 : Restart MySQL Server
service mysqld restart
Step 6 : Recheck new password of user root
mysql -u root -p
Now you completely reset password for Mysql.
Good luck!