First, change the my.cnf configuration file
1. Edit the/etc/my.cnf configuration file with the command, namely: VIM/ETC/MY.CNF or VI/ETC/MY.CNF
2. Add skip-grant-tables under [mysqld], then save and exit
3. Restart MySQL Services: Service mysqld restart
Second, change the root user name
1. After reboot, execute MySQL command to enter MySQL command line
2. Change the root user password
mysql>
update
mysql.
user
set
authentication_string=
password
(
‘123qwe‘
)
where
user
=
‘root‘
and
Host =
‘localhost‘
;
mysql> flush
privileges
;
mysql> quit;
* Note that there is no password field in the user table in the new MySQL database.
Instead, the encrypted user password is stored in the Authentication_string field
3. Use the Systemctl Stop Mysqld.service command to turn off the MySQL service.
4. Comment out the skip-grant-tables you just added in the/etc/my.cnf file using #
5. Restart the MySQL service using the systemctl start Mysqld.service command.
mysql5.7 root password forgotten after password change