1.在/etc/mysql/my.cnf中添加一行:

skip-grant-tables

2.重启mysql,进入mysql后:

USE mysql
UPDATE USER SET password=PASSWORD("新密码") WHERE USER='root';