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)
    
  • 相关阅读:
    这样的程序员创业有戏
    一个29岁总裁对大学生的16条忠告
    向C#的String类添加按字节截取字符串的扩展方法
    妙用SQL Server聚合函数和子查询迭代求和
    为什么要在定义抽象类时使用abstract关键字
    C# 抽象类
    C# 虚函数和重载函数
    在指定文本里记录内容
    静态和非静态方法
    抽象类
  • 原文地址:https://www.cnblogs.com/gshelldon/p/14073164.html
Copyright © 2011-2022 走看看