Modify vi /etc/my.cnf and add skip-grant-tables to log in to mysql without password
use mysql ;
update user set authentication_string=PASSWORD("123456") where user='root';
Modify vi /etc/my.cnf again, comment skip-grant-tables, restart mysql
mysql -uroot -p123456 login