在什么情况下,需要重置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. ubuntu-12.04.5-desktop-i386.iso:ubuntu-12.04.5-desktop-i386:安装Oracle11gR2

    ubuntu 桌面版的安装不介绍. 如何安装oracle:核心步骤和关键点. ln -sf /bin/bash /bin/sh ln -sf /usr/bin/basename /bin/basena ...

  2. Servlet3简介

    servlet基础知识:http://blog.csdn.net/chjttony/article/details/6086292 ServletContext相关知识:http://blog.csd ...

  3. logback.xml常用配置详解

    <?xml version="1.0" encoding="UTF-8"?><configuration debug="false& ...

  4. gtk界面设计

    一.GTK基本 #include <gtk/gtk.h> int main( int argc, char *argv[]) { GtkWidget *window; /*初始化整个GTK ...

  5. 【Cesium】天空盒子

    skyBox: new Cesium.SkyBox({ sources: { positiveX: 'static/image/skyBox/posx.jpg', negativeX: 'static ...

  6. 【NodeJS】http-server.cmd

    npm install http-server @echo off  start cmd /k "D:\Program Files\nodejs\node_global\http-serve ...

  7. MySQL on Linux 部署手册

    1. 背景 MySQL为开源数据库,因此可以基于源码实现安装.基于源码安装有更多的灵活性.也就是说我们可以针对自己的硬件平台选用合适的编译器来优化编译后的二进制代码,根据不同的软件平台环境调整相关的编 ...

  8. SQL筛选出同一学科的时间最新的记录

    1.建表语句 CREATE TABLE `score` ( `id` ) NOT NULL AUTO_INCREMENT, `student_id` ) ' COMMENT '学生表ID', `nam ...

  9. [NodeJS] Node.js 与 V8 的故事

    要说Node.js的历史,就不得不说说V8历史.在此之前我们先一句话描述一下什么是Node.js:Node.js是一个基于Google Chrome V8 Javascript引擎之上的平台,用以创建 ...

  10. Kafka producer拦截器(interceptor)

    Producer拦截器(interceptor)是个相当新的功能,它和consumer端interceptor是在Kafka 0.10版本被引入的,主要用于实现clients端的定制化控制逻辑. 对于 ...