誤刪除 mySQL 用戶解決辦法

誤刪除用戶解決辦法


刪除用戶


刪除用戶html

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服務並登陸mysql

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

恢復用戶


當登陸不上去首先停掉正在運行的數據庫sql

[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>

刷新受權表app

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

建立 root 超級用戶並退出ide

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服務spa

[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

啓動數據庫服務rest

[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

鏈接數據庫code

[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)

注意:以上只能在存在數據的時候使用,若是沒有數據直接初始化就能夠。

原文出處:https://www.cnblogs.com/daiyacheng1991/p/11779252.html

相關文章
相關標籤/搜索