在什么情况下,需要重置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  (): Access denied for user 'root'@'localhost' (using password: NO)

那么就换下面这种:

macdeMacBook-Pro:~ mac$ mysql -uroot -h127.0.0. -p
Enter password:
ERROR (): 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 id is
Server version: 5.7. Homebrew Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is 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';回车,出现以下的界面,说明修改成功。

mysql> UPDATE mysql.user SET authentication_string=PASSWORD('') WHERE User='root';
Query OK, row affected, warning (0.00 sec)
Rows matched: Changed: Warnings:
 

接下来输入FLUSH PRIVILEGES;回车,出现下面的界面

mysql> FLUSH PRIVILEGES;
Query OK, rows affected (0.01 sec)
 

最后,输入\q,退出。关闭第一个终端,回到系统的偏好设置,重新开启MySQL即可。

mysql> \q
Bye
macdeMacBook-Pro:~ mac$ mysql -uroot -h127.0.0. -p
Enter password:
ERROR (): Access denied for user 'root'@'localhost' (using password: YES)
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 id is
Server version: 5.7. Homebrew Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is 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';
Query OK, row affected, warning (0.00 sec)
Rows matched: Changed: Warnings: mysql> FLUSH PRIVILEGES;
Query OK, rows affected (0.01 sec) mysql> \q
Bye
macdeMacBook-Pro:~ mac$

Mac - MySQL初始密码忘记重置MySQL root密码的更多相关文章

  1. mysql忘记密码如何重置密码,以及修改root密码的三种方法

    1.先将MySQL停止. 命令:systemctl  stop mysqld       #停掉MySQL 命令:systemctl status mysqld         #查看状态 2.然后跳 ...

  2. [转帖]忘记了MariaDB root密码的解决办法

    忘记了MariaDB root密码的解决办法 https://www.cnblogs.com/liaojie970/p/6126322.html 貌似跟 mysql 是一样的. 1.停掉mariaDB ...

  3. [转帖]Ubuntu忘记超级用户root密码,重新设置密码

    Ubuntu忘记超级用户root密码,重新设置密码 版权声明:本文为博主原创文章,转载必须指明出处. https://blog.csdn.net/weixin_37909391/article/det ...

  4. Linux(Unix)密码策略问题导致root密码不能修改

    Linux(Unix)密码策略问题导致root密码不能修改 发布时间:  2016-01-19 浏览次数:  1034 下载次数:  5 用户修改了密码配置文件,导致root账户修改密码时报如下错误: ...

  5. mysql root密码忘记重置及相关注意事项

    1.使用mysqld_safe --skip-grant-tables跳过授权,进入mysql操作界面或者在配置文件mysqld 添加skip-grant-tables也行,找回后需要删除..恢复原样 ...

  6. Mysql(Linux服务器)root用户密码忘记重置方法

    MySQL是非常常见的开源数据库,使用者众多,若是不小心忘记了安装在服务器的mysql密码,无法登陆,应该如何重置呢?方法很简单,现在和大家分享下.(系统环境:CentOs 6.5  软件:Mysql ...

  7. MySQL忘记密码,或:root密码重置报错:mysqladmin: connect to server at 'localhost' failed的解决方案

    MySQL root密码重置报错:mysqladmin: connect to server at 'localhost' failed的解决方案   1  登陆失败,mysqladmin修改密码失败 ...

  8. mysql root密码忘记重置

    1.修改/etc/my.cnf文件 找到mysqld选项,增加子项skip-grant-tables 2.重新启动mysql服务 service mysqld restart 3.进入mysql 在s ...

  9. 在Ubuntu 18.04 下安装mysql,没有初始密码,重设root密码

    在Ubuntu 18.04 下安装mysql 不知道是由于mysql更新为新版还是.Ubuntu18.04中的特性,安装过程中没有设置密码的环节,在网络上找了半天,总算解决了!特此记录下来,以便以后查 ...

随机推荐

  1. Nine-patch

    http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch   This NinePatch defi ...

  2. 详解CorelDRAW中关于群组的操作

    CorelDRAW软件中的“群组”功能键主要用于整合多个对象.在进行比较复杂的绘图编辑时,通常会有很多的图形对象,为了方便操作,可以对一些对象设定群组.设定群组以后的多个对象,将被看作一个单独的对象. ...

  3. Redis集群版在Java中的应用

    1.配置redis集群 <?xml version="1.0" encoding="UTF-8"?> <redisCluster> &l ...

  4. Centos7.3.1611安装mysql5.7.18 rpm教程 并设置datadir

    一.卸载MariaDB CentOS7默认安装MariaDB而不是MySQL,而且yum服务器上也移除了mysql相关的软件包.因为MariaDB和MySQL可能会冲突,故先卸载MariaDB. 1. ...

  5. Linux的时间设置与同步

    http://www.cnblogs.com/liuyou/archive/2012/07/29/2614338.html

  6. 安装kafka集群

    1解压tar包 tar -zxvf kafka_2.-.tgz 2.进入config目录 3.配置server.properties文件 # Licensed to the Apache Softwa ...

  7. trim思考

    今天发现后台订单商品名称没有的时候出现了HTML代码,然后看了一下源代码(下图是简化版本的) <?php $name = trim('<span style="font-weig ...

  8. 中文解码Unicode

    package com.j1.search.utils; import java.io.UnsupportedEncodingException; import java.net.URLDecoder ...

  9. 深入浅出MFC——消息映射与命令传递(六)

    1. 消息分类: 2. 万流归宗——Command Target(CCmdTarget): 3. "消息映射"是MFC内建的一个信息分派机制.通过三个宏(DECLARE_MESSA ...

  10. php curl那点事儿

    curl是最常用功能之一初始化句柄 $ch = curl_init(); post 传$data 1. 如果$data是字符串,则Content-Type是application/x-www-form ...