在什么情况下,需要重置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. 最新Java面试题及答案整理

    基础篇 一.基本功 面向对象特征 封装,继承,多态和抽象 1. 封装 封装给对象提供了隐藏内部特性和行为的能力.对象提供一些能被其他对象访问的方法来改变它内部的数据.在 Java 当中,有 3 种修饰 ...

  2. geoserver入门

    1.什么是Universal Transverse Mercator system 翻译名叫做通用横轴魔卡托系统,通常称为UTM.这个投影系从中心子午线把世界分成一系列6度的纵向宽区域. 2.什么是w ...

  3. mysql 错误代码:1118解决方法

    错误描述: 错误代码: 1118Row size too large. The maximum row size for the used table type, not counting BLOBs ...

  4. 虚拟机中安装linux系统步骤

    参考:http://blog.csdn.net/u013111221/article/details/50856934 后面参考:http://blog.csdn.net/chenweitang123 ...

  5. phoenix连接hbase数据库,创建二级索引报错:Error: org.apache.phoenix.exception.PhoenixIOException: Failed after attempts=36, exceptions: Tue Mar 06 10:32:02 CST 2018, null, java.net.SocketTimeoutException: callTimeou

    v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...

  6. EXCEPTION:FATAL: UNABLE TO CREATE ‘…GIT/INDEX.LOCK’ FILE EXISTS

    FATAL: UNABLE TO CREATE ‘…GIT/INDEX.LOCK’ FILE EXISTS Hi, Today I will share you my other experience ...

  7. [web] spring boot 整合MyBatis

    1.maven依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="h ...

  8. Linux oracle数据库创建表空间、用户并赋予权限

    管理员用户登录oracle数据库 1.创建临时表空间 select name from v$tempfile;查出当前数据库临时表空间,主要是使用里面的存放路径: 得到其中一条记录/opt/oracl ...

  9. hadoop JOB的性能优化实践

    使用了几个月的hadoopMR,对遇到过的性能问题做点笔记,这里只涉及job的性能优化,没有接触到 hadoop集群,操作系统,任务调度策略这些方面的问题. hadoop MR在做大数据量分析时候有限 ...

  10. linux下使用ftp传递文件的shell脚本

    使用ftp传递文件,传递过程中防止对方取文件,后缀名为writing,传完后再改回来. #!/bin/bash dstpath=cnet ftpip="127.0.0.1" log ...