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