Today, when receiving a MySQL server, I found that I forgot the password of the root user of MySQL, looked for the data and sent the various documents without the root user password, so we need to change the root user password.
First verify that the server is in a secure state, that is, no one can connect to the MySQL database arbitrarily. Because the MySQL database is completely out of password-protected state during the reset of the root password of MySQL, other users can log in and modify the MySQL information arbitrarily.The safest state is to operate on the console of the server and unplug the network cable.
1. Modify MySQL Login settings:
The skip-grant-tables added to the paragraph in [mysqld]
# sed-i '/\[mysqld\]/a\skip-grant-tables '/etc/my.cnf
2. Restart Mysqld
# service Mysqld Restart
Shutting down MySQL. success!
Starting MySQL. success!
3. Log in and modify the root password of MySQL
#/usr/bin/mysql
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 1
Server version:5.6.19 Source Distribution
Copyright (c), the Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.
mysql> use MySQL;
Reading table information for completion of table and column names
Can turn off this feature to get a quicker startup with-a
Database changed
mysql> UPDATE user SET Password = Password (' doiido ') WHERE user = ' root ';
Query OK, 3 rows affected (0.01 sec)
Rows Matched:3 Changed:3 warnings:0
mysql> flush Privileges;
Query OK, 0 rows affected (0.01 sec)
Mysql> quit
Bye
4. Change the MySQL login settings back
Delete the skip-grant-tables you just added in the paragraph [mysqld]
# sed-i "/skip-grant-tables/d"/etc/my.cnf
5. Restart Mysqld
# service Mysqld Restart
Shutting down MySQL. success!
Starting MySQL. success!
At this point, you can use Root/doiido to log in.
MySQL forgot root user password under Linux