1.关闭mysql服务器
sudo /usr/local/mysql/support-files/mysql.server stop 或者系统偏好里有个 MySQL 里关闭
2.进入 /usr/local/mysql/bin 目录
cd /usr/local/mysql/bin
3.获取权限
sudo su
4.重启服务器
./mysqld_safe --skip-grant-tables &
5.重开个终端
mysql -uroot -p (提示输入密码时随便输入即可)
6.获取权限
flush privileges;
7.设置新密码
set password for 'root'@'localhost'=password('新密码');
作者:JoinPerson 链接:https://www.jianshu.com/p/47caaf07fdfa