mac忘记mysql初始密码怎么办_Mac - MySQL初始密码忘记重置MySQL root密码

在什么情况下,需要重置root密码呢?那就是我们忘记了。还有一种比较坑的,那就是笔者的这种情况。按照正常的情况下,MySQL安装完之后,会弹出一个对话框,显示着一个临时的root密码,但无论笔者如何重装MySQL,始终不给我一个临时的root的密码,导致笔者一直无法登陆MySQL,没办法,只能用硬的,那就是重置密码。

停止MySQL的服务,打开系统的偏好设置,找到MySQL 进去后,点击Stop MySQL Server即可。

step1:

苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server)

step2:

进入终端输入:cd/usr/local/mysql/bin/回车后 登录管理员权限 sudo su

回车后输入以下命令来禁止mysql验证功能 ./mysqld_safe --skip-grant-tables &回车后mysql会自动重启(偏好设置中mysql的状态会变成running)

开启两个终端,在第一个终端输入sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables,输入当前用户的密码:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

那么就换下面这种:

macdeMacBook-Pro:~ mac$ mysql -uroot -h127.0.0.1 -p

Enter password:

ERROR1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

然后在第二个终端输入sudo /usr/local/mysql/bin/mysql -u root,然后输入当前用户的密码后,出现以下的界面

macdeMacBook-Pro:~ mac$ sudo /usr/local/mysql/bin/mysql -u root

Password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection idis 3Server version:5.7.22Homebrew

Copyright (c)2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracleis a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type'help;' or '\h' for help. Type '\c'to clear the current input statement.

mysql>

然后输入命令UPDATE mysql.user SET authentication_string=PASSWORD('新密码') WHERE User='root';回车,出现以下的界面,说明修改成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值