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 -u root -p (提示输入密码时随便输入即可)
6. 拿到权限(可以修改密码)
flush privileges;
7.修改密码
SET PASSWORD FOR root@localhost = '123456';
8.退出mysql
quit;
9.重启mysql
/usr/local/mysql/support-files/mysql.server restart
参考链接:https://www.jianshu.com/p/cdfff359be47