centos 怎么退出init 3_Linux服务器上的mysql的root密码忘了怎么办?

如果我们忘记root密码提示ERROR 1045,应该怎么办呢?

  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 ~]#

复制代码

096b024de94c7cb6eae487a84a3084f4.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 保存并推出

复制代码

08fe545917baa1538207901b79247fe6.png重启数据库:

  1. stemctl  restart mysqld

复制代码

9404be7aebd48df06793549e137ae03c.png再次进入数据库,到密码界面直接回车,即可跳过密码进入:4db1334e17b95e071a0840acf54ec248.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)

复制代码

256b53e211db226d950f6342471fea11.png1.退出数据库,再次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>

复制代码

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

定制《接口自动化&性能测试 》 9月12小班开课!

原来接口测试可以这么玩呀!!!

轻松玩转性能测试,薪资涨上它2k

原来接口自动化测试这么简单!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值