mysql active exited_MySQL补充——忘记密码怎么办

MySQL补充——忘记密码怎么办

摘要:本文主要记录了在忘记密码时怎么办。

部分内容来自以下博客:

https://www.cnblogs.com/wuotto/p/9682400.html

关闭MySQL数据库

使用命令检查MySQL数据库是否已经关闭:

1 [root@localhost ~]# systemctl status mysql

出现“Active: inactive (dead)”表示数据库已关闭,如果是“Active: active (exited)”表示已开启,需要手动关闭:

1 [root@localhost ~]# systemctl stop mysql

修改MySQL的配置文件

找到MySQL的配置文件“my.cnf”,默认路径是:“/etc/my.cnf”。

打开文件并在“[mysqld]”下添加:

1 skip-grant-tables

这句话的作用是在登录MySQL的时候可以跳过密码直接登录。

保存修改并退出。

启动MySQL

使用命令启动MySQL:

1 [root@localhost ~]# systemctl start mysql

输入“mysql”即可进入数据库。

修改密码

连接“mysql”数据库,修改用户密码:

1 mysql>use mysql;2 Reading table information forcompletion of table and column names3 You can turn off this feature to get a quicker startup with -A4

5 Database changed6 mysql> update mysql.user set password=password('123456') where user='root';7 Query OK, 5 rows affected (0.00sec)8 Rows matched: 5 Changed: 5 Warnings: 0

9

10 mysql>

将root用户的密码设为123456。

刷新使改动生效:

1 mysql>flush privileges;2 Query OK, 0 rows affected (0.00 sec)

回改文件并重启

退出MySQL,重新打开“my.cnf”配置文件,删除“skip-grant-tables”,保存退出。

重启MySQL,需要密码登录,输入设置的密码即可:

1 [root@localhost ~]# vim /etc/my.cnf2 [root@localhost ~]# systemctl restart mysql3 [root@localhost ~]# mysql4 ERROR 1045 (28000): Access denied for user 'root'@'localhost'(using password: NO)5 [root@localhost ~]# mysql -u root -p6 Enter password:7 Welcome to the MySQL monitor. Commands end with ; or \g.8 Your MySQL connection id is 4

9 Server version: 5.6.45MySQL Community Server (GPL)10

11 Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.12

13 Oracle is a registered trademark of Oracle Corporation and/or its14 affiliates. Other names may be trademarks of their respective15 owners.16

17 Type 'help;' or '\h' for help. Type '\c' to clearthe current input statement.18

19 mysql>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值