首先确定自己homebrew 安装的 mysql 的路径:
我的是:
/usr/local/Cellar/mysql/5.7.22
首先输入
sudo /usr/local/Cellar/mysql/5.7.22/support-files/mysql.se
rver stop
可能会出现
ERROR! MySQL server PID file could not be found!
不用管他
然后进入bin目录
cd /usr/local/Cellar/mysql/5.7.22/bin
输入
sudo su
进入sh-3.2
输入./mysqld_safe --skip-grant-tables &
出现的是
2018-05-14T04:29:02.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2018-05-14T04:29:02.6NZ mysqld_safe mysqld from pid file /usr/local/var/mysql/jijiamingdeMacBook-Pro.local.pid ended
不同用户可能有一点区别,不管他,contrl+d 退出
接着 输入
alias mysql=/usr/local/mysql/bin/mysql
mysql
use mysql
flush privileges;
set password for 'root'@'localhost'=password('新密码');
输入命令一直是query ok ,就说明你操作成功了
最后在 试试看使用新密码登录root 账号