1. Edit the my.cnf file and add a line of skip-grant-tables under [mysqld]
vim /etc/my.cnf
2. Restart mysql
service mysqld restart
3. Log in to mysql without entering a password
mysql -uroot -p
4. Modify the root user login password
mysql> use mysql; mysql> update user set authentication_string=password('123456') where user='root';
5. Delete the skip-grant-tables added in the first step
6. restart mysql
service mysqld restart
Change password completed