linux centos mysql 5.7 忘记root 密码

https://www.bilibili.com/video/BV1Sv411r7vd?p=143
linux centos mysql 5.7 忘记root 密码 ,如何找回

找回步骤

step1 登录发现忘记Mysql 密码

[root@shell38 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-03-27 00:26:42 PDT; 4min 28s ago
     Docs: man:mysqld(8)
-----  忘记密码了,登录不了MySQL5.7 
[root@shell38 ~]# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

step2 进入 /etc/my.cnf 文件 加入一条指令 skip-grant-tables

[root@shell38 ~]# vim /etc/my.cnf
... 
...
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
pid-file=/var/run/mysqld/mysqld.pid
# and the blow to skip password
skip-grant-tables             -----------------增加这句话

step 3 重启 MySQL 服务 ,验证可以用空密码登录

[root@shell38 ~]# systemctl restart mysqld
[root@shell38 ~]# mysql -u root -p
Enter password:   ------此时输入一个空密码就进入mysql 里面了 
mysql> 

step4 用空密码登录后进入 mysql 库 user 表 更改 root 用户的authentication_string 密码值

[root@shell38 ~]# mysql -u root -p
Enter password: ------此时输入一个空密码就进入mysql 里面了 
mysql> show databases;--------------显示库列表 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| leodb              |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.69 sec)

mysql> use mysql;-------------------进入mysql库
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;--------------------显示mysql库下面的表的个数
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| engine_cost               |
| event                     |
| func                      |
| general_log               |
| gtid_executed             |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| server_cost               |
| servers                   |
| slave_master_i
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值