误删除用户解决办法


删除用户


删除用户

mysql> truncate mysql.user;
Query OK, 0 rows affected (0.05 sec)

mysql> select user,host from mysql.user;
Empty set (0.00 sec)

重启mysql服务并登录

[root@db01 ~]# systemctl restart mysqld
[root@db01 ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
#登录错误

恢复用户


当登录不上去首先停掉正在运行的数据库

[root@db01 ~]# systemctl stop mysqld
[root@db01 ~]# ps -ef |grep mysqld
root       7905   7664  0 03:22 pts/1    00:00:00 grep --color=auto mysqld

跳过授权表,跳过网络启动数据库

[root@db01 ~]# mysqld_safe --skip-grant-tables --skip-networking &     -----跳过授权表,跳过网络
[1] 7908
[root@db01 ~]# 191101 03:26:40 mysqld_safe Logging to '/application/mysql/data/db01.err'.
191101 03:26:40 mysqld_safe Starting mysqld daemon with databases from /application/mysql/data

连接数据库

[root@db01 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.44 Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

刷新授权表

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

创建 root 超级用户并退出

mysql> grant all on *.* to root@'localhost' identified by '123' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Bye

停止mysql服务

[root@db01 ~]# mysqladmin -uroot -p123 shutdown
Warning: Using a password on the command line interface can be insecure.
191101 03:58:41 mysqld_safe mysqld from pid file /application/mysql/data/db01.pid ended
[1]+ Done                   mysqld_safe --skip-grant-tables --skip-networking

[root@db01 ~]# ps -ef |grep mysqld
root       8078   7664  0 03:59 pts/1    00:00:00 grep --color=auto mysqld

启动数据库服务

[root@db01 ~]# systemctl start mysqld
[root@db01 ~]# ps -ef |grep mysqld
mysql      8085      1  8 03:59 ?        00:00:00 /application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
root       8108   7664  0 03:59 pts/1    00:00:00 grep --color=auto mysqld

连接数据库

[root@db01 ~]# mysql -uroot -p123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.44 Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

查看创建的用户的权限

mysql> select * from mysql.user\G
*************************** 1. row ***************************
                Host: localhost
                User: root
            Password: *23AE809DDACAF96AF0FD78ED04B6A265E05AA257
          Select_priv: Y
          Insert_priv: Y
          Update_priv: Y
          Delete_priv: Y
          Create_priv: Y
            Drop_priv: Y
          Reload_priv: Y
        Shutdown_priv: Y
        Process_priv: Y
            File_priv: Y
          Grant_priv: Y  -------------------------如果是N 就是不是超级用户权限
      References_priv: Y
          Index_priv: Y
          Alter_priv: Y
        Show_db_priv: Y
          Super_priv: Y
Create_tmp_table_priv: Y
    Lock_tables_priv: Y
        Execute_priv: Y
      Repl_slave_priv: Y
    Repl_client_priv: Y
    Create_view_priv: Y
      Show_view_priv: Y
  Create_routine_priv: Y
  Alter_routine_priv: Y
    Create_user_priv: Y
          Event_priv: Y
        Trigger_priv: Y
Create_tablespace_priv: Y
            ssl_type:
          ssl_cipher:
          x509_issuer:
        x509_subject:
        max_questions: 0
          max_updates: 0
      max_connections: 0
max_user_connections: 0
              plugin: mysql_native_password
authentication_string:
    password_expired: N
1 row in set (0.00 sec)

注意:以上只能在存在数据的时候使用,如果没有数据直接初始化就可以。

误删除 mySQL 用户解决办法的更多相关文章

  1. mysql03--误删除了所有用户解决办法

    误删除了所有用户解决办法 第一种方法(企业常用) 1.将数据库down掉 [root@db03 mysql]# /etc/init.d/mysqld stop Shutting down MySQL. ...

  2. 二.误删除MySQL用户,恢复方法

    误删除MySQL用户导致无法进入数据库 一.方法一 1.停止数据库 [root@db02 ~]# /etc/init.d/mysqld stop 2.跳过授权表,跳过网络启动数据库 [root@db0 ...

  3. 导出oracle 到 mysql的解决办法

    导出oracle 到 mysql的解决办法 使用sqluldr2 命令如下sqluldr2 USER=weibh/1234@dydb file=c:\1.txt sql=sql.sql   FORMA ...

  4. [08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up IDEA2019的database插件无法链接mysql的解决办法(08001错误)

    [08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up. 点击这里 ...

  5. 【数据库开发】is not allowed to connect to this MySQL server解决办法

    ERROR 1130: Host '192.168.1.3′ is not allowed to connect to this MySQL server这是告诉你没有权限连接指定IP的主机,下面我们 ...

  6. Sql Server 孤立用户解决办法

    Sql Server 孤立用户 是我们经常遇到的事情,今天详细的梳理了下,希望能帮到你 当把用户数据库从一台 Sql Server 使用备份和恢复的方式迁移到另一台服务器.数据库恢复以后,原先用户定义 ...

  7. 在centos6.5下用nginx无法连接zabbix与mysql的解决办法

    一般情况下默认的webserver是apache.zabbix也不例外,官方文档全都是推荐用apache. 如果执意用nginx来做webserver的话,php引导需要再安装一个php-fpm.而且 ...

  8. mysql 死锁解决办法

    查询表的时候,发现一圈圈转啊转,就是不出来数据,猜测表被锁住 解决办法 : mysql> show processlist ; mysql> kill 4;       说明 : 4为 i ...

  9. IDEA的database插件无法链接mysql的解决办法(08001错误)

    1.问题 首先先说问题,用navicat链接数据库正常,mysql控制台操作正常,但是用IDEA的数据库插件链接一直报 08001 错误,具体见下图: 错误:Connection to eshop@l ...

随机推荐

  1. linux添加默认网关

    运维常用linux命令整理 1.临时添加 route add default gw 192.168.1.4 2.永久添加 vim /etc/sysconfig/network GATEWAY=192. ...

  2. 错误:java.lang.NoClassDefFoundError: org/jaxen/JaxenException

    tomcat运行时候报错: java.lang.NoClassDefFoundError: org/jaxen/JaxenException at org.dom4j.DocumentFactory. ...

  3. Spring框架(三)

    对象依赖关系 Spring中,如何给对象的属性赋值?  [DI, 依赖注入] 1) 通过构造函数 2) 通过set方法给属性注入值 3) p名称空间 4)自动装配(了解) 5) 注解 代码示例: &l ...

  4. layui-table 对表格数据进行处理之后的排序问题

    使用layui table过程中,将某一列的数据格式进行转换,或者将0/1状态改为是/否,或者将数字改为星星评分显示的时候都会遇到一个问题,我的表格数据转换成其他形式,同时设置了sort:true,此 ...

  5. 通过父级id获取到其下所有子级(无穷级)——Mysql函数实现

    [需求]某用户只能查看其自己信息及其下级信息,涉及通过该用户所在部门获取其下所有部门(多层)id集合. 步骤一:对数据库进行设置: set global log_bin_trust_function_ ...

  6. SpringBootSecurity学习(20)前后端分离版之OAuth2.0刷新token

    刷新token 前面的例子和配置都是从头开始申请授权码和令牌,现在来看一下如何根据获取令牌时,回参中的 refresh_token 来刷新令牌.现在在项目中配置的是内存模式的默认用户名密码,第一步先改 ...

  7. 安装sublime插件安装不上遇到的各种坑

    为了学习VUE , 发现没有高亮代码, 百度原来需要安装插件,安装过程中遇到了各种坑,记录下来避免大家踩坑, 首先用代码安装快捷键  ctrl+`   粘贴代码 import urllib.reque ...

  8. 什么是回流(重排 reflow)?什么是重绘(repaint)?如何减少回流、重绘?

    什么是回流(重排 reflow)? 回流(重排 reflow):对DOM树进行渲染,只要修改DOM或修改元素的形状大小,就会触发reflow,reflow的时候,浏览器会使已渲染好受到影响的部分失效, ...

  9. Making the Grade POJ - 3666

    A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ would l ...

  10. 【C语言笔记】#define与typedef的区别

    1.#define define是预处理指令,在编译时不进行任何检查,只进行简单的替换 宏定义的一般形式为: #define 宏名 字符串 这里所说的字符串是一般意义上的字符序列,不要和C语言中的字符 ...