- 拷贝support-files/my-default.cnf到/etc/my.cnf
- vim 编辑/etc/my.cnf,尾部追加一行
skip-grant-tables
- 重启MySQL服务
进入MySQL,重置密码
mysql -u root #进入MySQL update user set authentication_string=PASSWORD('newpass') where User='root' #5.7.6以上 update user set password=PASSWORD('newpass') where User='root'; #5.7.5 之前
- 退出,删除在/etc/my.cnf尾部追加的内容(skip-grant-tables),保存退出,重启MSYQL服务
进入MSYQL,使用新密码登录
mysql -uroot -p mysql> SET PASSWORD = PASSWORD('your_new_password');# 否则在创建数据库的时候会报如下错误
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
PS:参考链接
https://www.skyf.org/reset-mysql579-root-password/
http://stackoverflow.com/questions/33467337/reset-mysql-root-password-using-alter-user-statement-after-install-on-mac