1. 关闭mysql服务
sudo /usr/local/mysql/support-files/mysql.server stop 或者系统偏好里有个 MySQL 里关闭
2.来到mysql目录下
cd /usr/local/mysql/bin
3.得到权限
sudo su
4.重启mysql服务
./mysqld_safe --skip-grant-tables & 或者在系统编号中开启
5.重开终端
mysql -uroot -p (提示输入密码时随便输入即可
6. 拿到权限(可以修改密码)
flush privileges;
7.修改密码
set password for 'root'@'localhost'=password('新密码');
set password for 'root'@'localhost'=password('新密码');