Log in to the server first: Linux
1. Modify the configuration file
Vi/etc/my.cnf
Add a sentence to the paragraph in [mysqld]
Skip-grant-tables
2. Save Restart MySQL
Service mysqld Restart
3. Change the root password
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 Mysql.user Set Authentication_string=password (' * * * ') where user= ' root ';
Query OK, 0 rows affected, 1 Warning (0.00 sec)
Rows matched:2 changed:0 warnings:1
Mysql> exit
3. Delete the skip-grant-tables in the configuration file
4. Save restart MySQL
Service mysqld Restart
5. Log in to MySQL and set login permissions
Mysql-u root-p
Enter Password:
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 5
Server version:5.7.15 MySQL Community Server (GPL)
Copyright (c), 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.
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql> GRANT all privileges on . To ' root ' @ '% ' identified by ' ky123456ky+-' (' with GRANT OPTION;
Query OK, 0 rows affected, 1 Warning (0.00 sec)
mysql> flush Privileges;
Query OK, 0 rows Affected (0.00 sec)
Mysql-5.7,root user forgot password handling