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)
    
  • 相关阅读:
    遇到项目上面有叉,但是找不到错误的原因
    遇到build的问题
    遇到scan configurtation CDT builder等的错误
    遇到attemp to invoke virtual method
    遇到looper之类关于消息循环的
    Linux与Windows信息交互快捷方法
    并行查询
    PostgreSQL 事务管理的MVCC
    Linux安装memcached
    Linux 安装 Redis
  • 原文地址:https://www.cnblogs.com/gshelldon/p/14073164.html
Copyright © 2011-2022 走看看