1.关闭mysql服务
sudo /usr/local/mysql/support-files/mysql.server stop
2.安全模式启动mysql
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
3.新开一个终端启动mysql,此时不需要密码,重置密码
FLUSH PRIVILEGES;SET PASSWORD FOR root@'localhost' = PASSWORD('重新设置的密码');
重启ok