MAC 中mysql密码忘记解决办法

MAC 中mysql密码忘记解决办法

方法一:在mysql官网直接下载dmg文件进行安装,忘记密码

1.关闭mysql服务器
sudo /usr/local/mysql/support-files/mysql.server stop
2.进入目录
cd /usr/local/mysql/bin
3.获取权限
sudo su
4.重启服务器
./mysqld_safe --skip-grant-tables &
5.control + D退出编辑
6.配置短命令
alias mysql=/usr/local/mysql/bin/mysql
7.进入mysql命令模式
mysql
8.进入mysql数据库
use mysql
9.获取更改权限
flush privileges;
10.重置密码
set password for 'root'@'localhost'=password('新密码');

方法二、直接卸载mysql进行重新下载安装

1.卸载mysql
 sudo rm /usr/local/mysql

 sudo rm -rf /usr/local/var/mysql

 sudo rm -rf /usr/local/mysql*

 sudo rm -rf /Library/StartupItems/MySQLCOM

 sudo rm -rf /Library/PreferencePanes/My*

 vim /etc/hostconfig and removed the line MYSQLCOM=-YES-rm -rf ~/Library/PreferencePanes/My*

 sudo rm -rf /Library/Receipts/mysql*

 sudo rm -rf /Library/Receipts/MySQL*

 sudo rm -rf /var/db/receipts/com.mysql.*

2.重新安装mysql

下载url:https://dev.mysql.com/downloads/file/?id=486026

posted @ 2019-05-19 21:01  emos  阅读(1934)  评论(0编辑  收藏  举报