mysql.server stop
mysqld_safe --skip-grant-tables
mysql -uroot -p
UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root'; FLUSH PRIVILEGES;
这里需要注意一点,MySQL5.7版本字段名换了,Password改为authentication_string即可,即:
UPDATE mysql.user SET authentication_string=PASSWORD('NewPassword') WHERE User='root'; FLUSH PRIVILEGES;
mysql.server start
mysql -uroot -pnewpassword