Mac上MySQL忘记root密码一系列骚操作之后只能重装
|
字数总计:
1763
|
阅读时长:
1分钟
|
阅读量:
560
这篇文章距离最后更新已过45 天,如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!
- 卸载并完全删除
brew services stop mysql
ps -ax | grep mysql
kill mysql
brew remove mysql
brew cleanup
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /usr/local/mysql*
sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
下面的在我的文件夹中完全没有
subl /etc/hostconfig`
# Remove the line MYSQLCOM=-YES-
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*
重启
- 安装
brew install mysql
mysql.server start #停止服务mysql.server stop 或 brew services stop mysql
Starting MySQL
. SUCCESS!
- 登录并改密
mysql -u root #安装完成默认免密登录
alter user 'root'@'localhost' identified with mysql_native_password by 'root'; #8.0版本改密
Query OK, 0 rows affected (0.00 sec)
- 改密成功
exit;
退出MySQL- 重新连接MySQL:
mysql -u root -p
- 创建用户并指定对某一数据库有权限(在root用户下进行)
CREATE USER 'passwd' IDENTIFIED BY '123456'; #用户名passwd,密码123456
select user(); #查看当前用户
select user,host from mysql.user; #查看MySQL中所有用户
show grants for 'passwd'@'%'; #查看用户passwd的权限信息
grant select,insert,update,delete,create,alter on test.* to 'passwd'; #授予passwd查询和添加test库的权限
grant all privileges on test.* to 'passwd'@'%' identified by "123456" with grant option; #授予passwd对test库所有操作
- 导入数据库
mysql -uroot -p123456 test < mydb.sql