mysql破密和root用户被删除了的恢复

mysql数据库破密


MySQL密码恢复及设置
1.停止MySQL服务程序。
2.跳过授权表启动MySQL服务程序
skip-grant-tables(添加在配置文件)
3.重设root密码(更新user表记录)
4.以正常方式重启MySQL服务程序

[root@host50 ~]#systemctl  stop  mysqld
[root@host50 ~]#vim /etc/my.cnf

[mysqld]
...
skip-grant-tables             //跳过授权表启动MySQL服务程序
...

[root@host50 ~]#systemctl  start  mysqld
[root@host50 ~]#mysql
mysql> update  mysql.user  set  authentication_string=password("新密码") where  user="root"  and host="localhost";
mysql> flush  privileges;     //更新
mysql> quit;
[root@host50 ~]#mysql -uroot -p
Enter password:

root用户被删了的恢复
当删除mysql.user中的root后所有用户均没有权限时可进行跳过授权表启动Mysql服务进程

]#mysql
mysql> flush privileges;
 mysql> grant all privileges on *.* to root@'localhost' identified by '123456' with grant option;  
mysql> flush privileges;
mysql> quit;



设置数据库管理员root的密码
[root@host50 ~]# mysqladmin -hlocalhost -uroot -p password "654321"
Enter password: ——这里输入旧密码(这个必须记住才可以修改)
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
mysqladmin: unable to change password; error: 'Your password does not satisfy the current policy requirements'
报错信息是密码规则不符合密码规则

[root@host50 ~]# mysqladmin  -hlocalhost -p password "123qqq...A"
Enter password: 
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
警告明文登陆不安全

也可以修改配置文件
命令行操作:
systemctl stop mysqld
vim /etc/my.cnf
[mysql]
 validate_password_policy=0
validate_passwo rd_length= 6
:wq
systemctl start mysqld
[root@host50 ~]# mysqladmin  -hlocalhost -uroot -p password "123456"
Enter password: 
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
明文登陆,提示不安全

再次登陆验证:
[root@host50 ~]# mysql -uroot -p
Enter password: 


恢复管理员root密码:
修改配置文件,跳过密码登陆
命令行操作:
systemctl  stop mysqld
vim /etc/my.cnf
[mysql]
skip-grant-tables
:wq
systemctl start mysqld

查看密码库的连接密码:
mysql> select host,user,authentication_string from mysql.user;
+-------------+-----------+-------------------------------------------+
| host        | user      | authentication_string                     |
+-------------+-----------+-------------------------------------------+
| localhost   | root      | *F19C699342FA5C91EBCF8E0182FB71470EB2AF30 |
| localhost   | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| 192.168.4.% | admin     | *F19C699342FA5C91EBCF8E0182FB71470EB2AF30 |
| %           | webuser   | *F19C699342FA5C91EBCF8E0182FB71470EB2AF30 |
+-------------+-----------+-------------------------------------------+
修改密码(通过更改表记录的方式)
mysql> update mysql.user set authentication_string=password("123456") where user="root" and host="localhost";
Query OK, 0 rows affected, 1 warning (0.03 sec)
Rows matched: 1  Changed: 0  Warnings: 1

刷新记录
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)

不叫选项就会把全部的密码都修改
mysql> update mysql.user set authentication_string=password("123456");
Query OK, 4 rows affected, 1 warning (0.04 sec)
Rows matched: 4  Changed: 4  Warnings: 1

[root@host50 ~]# systemctl  stop mysqld
[root@host50 ~]# vim  /etc/my.cnf
[root@host50 ~]# systemctl  restart  mysqld
再一次跳过密码登陆就不会成功
[root@host50 ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
登陆验证:
[root@host50 ~]# mysql -uroot -p
Enter password: 



补充知识: 是通过加密函数进行加密
mysql> select "123456"
    -> ;
+--------+
| 123456 |
+--------+
| 123456 |
+--------+
1 row in set (0.00 sec)

mysql> select password("123456");
+-------------------------------------------+
| password("123456")                        |
+-------------------------------------------+
| *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-------------------------------------------+
1 row in set, 1 warning (0.00 sec)














































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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维螺丝钉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值