zoukankan      html  css  js  c++  java
  • 企业案例-Mysql误删除用户表如何恢复

    1.不小心删除了mysql所有用户

    mysql> delete from mysql.user where 1=1;
    Query OK, 5 rows affected (0.00 sec)
    
    #删除用户以后还是可以登陆,但是不要重启
    

    2.解决方式一:

    1)停止数据库

    #抽根烟冷静一下
    [root@db02 scripts]# systemctl stop mysqld
    

    2)跳过授权表和网络启动

    [root@db02 scripts]# mysqld_safe --skip-grant-tables --skip-networking &
    

    3)插入新的用户

    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');
    

    4)重启启动数据库

    [root@db02 scripts]# mysqladmin shutdown
    200709 16:27:19 mysqld_safe mysqld from pid file /usr/local/mysql/data/db02.pid ended
    [1]+  Done                    mysqld_safe --skip-grant-tables --skip-networking
    [root@db02 scripts]# systemctl start mysqld
    

    3.解决方式二:

    1)停止数据库

    #抽根烟冷静一下
    [root@db02 scripts]# systemctl stop mysqld
    

    2)跳过授权表和网络启动

    [root@db02 scripts]# mysqld_safe --skip-grant-tables --skip-networking &
    

    3)授权一个新用户

    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> grant all on *.* to root@'localhost' identified by '123' with grant option;
    Query OK, 0 rows affected (0.00 sec)
    
  • 相关阅读:
    小兔生仔和汽水换瓶的两个算法
    dpi 编程
    作者赠送的《我的第一本c++书》收到啦
    什么是程序员的优良品质
    如何把事情做对?
    学习应有的态度
    魔方数算法
    我的第二本c++教科书
    如何处理人际关系
    电动玩具的开发思路
  • 原文地址:https://www.cnblogs.com/gshelldon/p/14073164.html
Copyright © 2011-2022 走看看