1. 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 was completely password-protected during the reset of the root password for MySQL?
Status, other users can also log in and modify MySQL information arbitrarily. Can I use MySQL pair?
External ports are closed, and the method of stopping Apache and all user processes implements the server's quasi-security?
State. The safest state is to operate on the console of the server and unplug the network cable.
If it's a cloud server rented online, we'll modify it remotely.
2. Modify the login settings for MySQL:?
#vim/etc/my.cnf?
Add a sentence to the paragraph in [mysqld]: Skip-grant-tables?
For example:?
[Mysqld]?
Datadir=/var/lib/mysql?
Socket=/var/lib/mysql/mysql.sock?
Skip-grant-tables?
Save and Exit VI.
3. Restart mysqld?
#service mysqld restart?
stopping MySQL: [OK]?
Starting MySQL: [OK]
or appear:
Redirecting To/bin/systemctl restart Mysqld.service
4. Log in and modify the root password of MySQL?
#mysql?
Welcome to the MySQL Monitor. Commands End With; Or \g.?
Your MySQL Connection ID is 3 to server version:3.23.56?
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the buffer.
mysql> use MySQL;?
Database changed?
mysql> UPDATE user SET Password = Password (? ') 123456 '?) WHERE User = ' root ';? (Note that the single quotation mark in parentheses is the password you want to reset)
Query OK, 0 rows Affected (0.00 sec)?
Rows matched:5 changed:0 warnings:0?
mysql> flush privileges;?
Query OK, 0 rows affected (0.01 sec)?
Mysql> quit
Bye
5. Change MySQL login settings back?
#vim/etc/my.cnf?
Delete the skip-grant-tables you just added in the paragraph [mysqld]?
Save and exit Vim
6. Restart mysqld?
#service mysqld restart?
stopping MySQL: [OK]?
Starting MySQL: [OK]
Or:
Redirecting To/bin/systemctl restart Mysqld.service
7. Check if the new password is active
Input mysql-u root-p Carriage return
Then enter a new password, return, such as modify the success
What do I do if I forget to connect MySQL password in linux?