目   录

方式一

方式二


方式一


6、假设系统root用户的密码忘记了,在单用户模式下重新设置root用户的登录密码。

启动Linux虚拟机,进入选择系统菜单:

centos7中mysql忘记密码 centos7忘记登录密码_centos

②在启动界面,按 “e”进入如下界面:

centos7中mysql忘记密码 centos7忘记登录密码_root_02

centos7中mysql忘记密码 centos7忘记登录密码_centos7中mysql忘记密码_03

③找到Linux 16的那一行,将ro改为rw init=/sysroot/bin/sh:

centos7中mysql忘记密码 centos7忘记登录密码_root_04

centos7中mysql忘记密码 centos7忘记登录密码_centos_05

按下 Control+X ,使用单用户模式启动。

④重置密码,重启虚拟机:【重置密码时,出现中文乱码的情况:我是瞎蒙的,密码:“songshuhang”,输入两次密码(第二次是确认密码),就可以了。设置的密码,不能太短、太简单!】

centos7中mysql忘记密码 centos7忘记登录密码_乱码_06

重置密码---中文乱码

centos7中mysql忘记密码 centos7忘记登录密码_centos7中mysql忘记密码_07

方式二


在使用centos系统的时候有时候太久没用忘记登录密码了,这时候该怎么办呢?下面就来教教大家怎么重置root管理员的密码

1、 启动系统,在GRUB2引导画面,按E键,编辑引导项

centos7中mysql忘记密码 centos7忘记登录密码_root_08

2、删除linux16这一行最后的 rhgb和 quiet参数(在UEFI系统中是linuxefi),删除rhgb和quiet这两个参数是为了显示系统信息

centos7中mysql忘记密码 centos7忘记登录密码_centos7中mysql忘记密码_09

3、 在zh_CN.UTF-8后面添加以下参数:rd.break enforcing=0

centos7中mysql忘记密码 centos7忘记登录密码_centos_10

4、 接着按CTRL+X用改变的参数引导系统,在/sysroot/文件系统被挂载为只读时,是不能改变密码的,因为文件系统为不可写入。重新挂载文件系统为可写入。mount -o remount,rw /sysroot

centos7中mysql忘记密码 centos7忘记登录密码_乱码_11

5、 文件系统被重新挂载为可写,输入chroot /sysroot改变文件系统的root

centos7中mysql忘记密码 centos7忘记登录密码_乱码_12

6、输入passwd命令,命令行会提示改变root密码。注意:如果系统不能写入,passwd提示下面的错误信息:Authentication token manipulation error

#如果输入密码太短会提示信息:The password is shorter than 8 characters

#如果两次输入密码不匹配会提示信息:Sorry,passwords do not match

#如果是中文环境这两条提示信息会是乱码(我这里就是中文的所以是乱码)

centos7中mysql忘记密码 centos7忘记登录密码_乱码_13

7、 更新passwd文件会导致SELinux安全上下文文件错误。键入以下命令:touch /.autorelabel在下次系统引导前重新标记所有文件

centos7中mysql忘记密码 centos7忘记登录密码_linux_14

8、 .重新挂载系统为只读:mount -o remount,ro /

centos7中mysql忘记密码 centos7忘记登录密码_centos7中mysql忘记密码_15

9、键入exit命令退出chroot环境,再输入exit命令完成初始化,完成系统引导输入新密码