企业中误删除所有用户,如何恢复?
[root@db02 ~]# systemctl stop mysqld
#1.跳过授权表和网络启动
[root@db02 ~]# mysqladmin shutdown
[root@db02 ~]# mysqld_safe --skip-grant-tables --skip-networking &
#记住这里切勿执行下面这条命令
#这条命名表示只跳过授权表启动
#随便一服务器都可以连接数据库
#在其他服务器上可以测试 mysql -uroot -h 172.16.1.52
#[root@db02 ~]# mysqld_safe --skip-grant-tables &
#进入数据库 自己指定用户密码
mysql> insert into mysql.user values ('localhost','root',PASSWORD('123'),
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'',
'',
'',
'',0,0,0,0,'mysql_native_password','','N');
#查看插入用户的权限
mysql> select * from mysql.user\G
[root@db02 ~]# mysqladmin shutdown
[root@db02 ~]# systemctl start mysqld
[root@db02 ~]# mysql -uroot -p123
[root@db02 ~]# systemctl stop mysqld
#1.跳过授权表和网络启动
[root@db02 ~]# mysqladmin shutdown
[root@db02 ~]# mysqld_safe --skip-grant-tables --skip-networking &
#1.授权时直接加上参数包含 grant 权限
mysql> grant all on *.* to root@'localhost' identified by '123' with grant option;
Query OK, 0 rows affected (0.00 sec)
#2.查看用户
mysql> select user,host from mysql.user;
或者
#1.刷新授权表
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#2.管理员用户中授权权限为 N,所以要修改这个值
mysql> update mysql.user set Grant_priv='Y' where Host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
[root@db02 ~]# mysqladmin shutdown -uroot -p123
[root@db02 ~]# systemctl start mysqld
[root@db02 ~]# mysql -uroot -p123
本文来自博客园,作者:六月OvO,转载请注明原文链接:https://www.cnblogs.com/chenlifan/p/13849286.html

浙公网安备 33010602011771号