centos 怎么退出init 3_【编测编学】Linux服务器上的mysql的root密码忘了怎么办?

点击上方加关注,软件测试不迷路

1e7787f7d8cf1a60880ccead37f6a508.gif

忘记root密码提示ERROR 1045:

f1b5598e53538a98ea845a23b811db59.gif
  1. [root@VM_0_15_centos ~]# mysql -uroot -p

  2. Enter password: 

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

  4. [root@VM_0_15_centos ~]#

复制代码

3784365655bdddb8d5734fcd5c6c3683.png

修改配置文件my.cnf,在配置文件[mysqld]下添加skip-grant-tables,重启MySQL服务即可免密码登录其中--skip-grant-tables 选项前面曾经介绍过,意思是启动 MySQL 服务的时候跳过权限表认证。 启动后,连接到 MySQL 的 root 将不需要口令。
  1. vi  my.cnf

  2. 按insert进入编辑模式

  3. 在[mysqld]下增加一行输入:

  4. skip-grant-tables

  5. 按ESC切到命令模式 :wq 保存并推出

复制代码

3adcb6d130df3a20878c2324c8213293.png 重启数据库:

  1. stemctl  restart mysqld

复制代码

cdb5924b0bd0897be13cd7749683acf6.png 再次进入数据库,到密码界面直接回车,即可跳过密码进入:6e148c34ed35553ee89ffb4e4971b64c.png 

  1. mysql> update mysql.user set authentication_string=password('1234567') where user='root' and host='localhost';

  2. Query OK, 1 row affected, 1 warning (0.01 sec)

  3. Rows matched: 1  Changed: 1  Warnings: 1

  4. mysql> flush privileges;

  5. Query OK, 0 rows affected (0.03 sec)

复制代码

2985ac86264c44f244895e15ace2f27d.png 1.退出数据库,再次vi  my.cnf 注释掉skip-grant-tables,保存退出2.重启数据库3.再次使用刚刚设置的密码登录:

  1. mysql> exit

  2. Bye

  3. [root@VM_0_15_centos ~]# vi /etc/my.cnf

  4. [root@VM_0_15_centos ~]# systemctl  restart mysqld

  5. [root@VM_0_15_centos ~]# mysql -uroot -p1234567

  6. mysql: [Warning] Using a password on the command line interface can be insecure.

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

  8. Your MySQL connection id is 2

  9. Server version: 5.7.30 MySQL Community Server (GPL)

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

  11. Oracle is a registered trademark of Oracle Corporation and/or its

  12. affiliates. Other names may be trademarks of their respective

  13. owners.

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

  15. mysql> 

复制代码

如下图所示9ee3dd9422233e9f443ee39a7b77e028.png 到此数据库已成功修改了root账号密码

e385670c8d1f3cd5478b52c66fd56758.gif

5dcf21abedd518a5d1505a54180f0060.png

e385670c8d1f3cd5478b52c66fd56758.gif

现在对linux有一定了解了吗?

f1b5598e53538a98ea845a23b811db59.gif

想了解更多,请登录www.bcbxhome.com

在测试论坛里寻找更多文章!

c5e72c66c860e222067b322b90c7ec50.gif

如果你对编测编学本期干货产生了兴趣

就请

搜索下方联系,点击下方链接,快点加入我们吧!

03a7dcf68c8357f42053d8894c8e9ac8.gif

微信:mmr0603

电话:17791330189

QQ大群:925205234

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值