mysql5.7 误删管理员root%'localhost'账户

博客介绍了一系列MySQL操作,包括停止数据库,以 --skip-grant-tables 启动mysql进程,用空密码的root用户连接MySQL并更改root口令,查看新添加用户的权限,最后重启mysql服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1)停止数据库

kill Mysql进程

2)在加上 --skip-grant-tables启动mysql 进程加粗样式

其中--skip-grant-tables意思是启动MySQL 服务的时候跳过权限表认证。
启动后,连接到MySQL 的root 将不需要口令
cd /mysqldata/mysql/bin
./mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --skip-grant-tables&

3)用空密码的root 用户连接到MySQL,并且更改root 口令

mysql -uroot -p 
use mysql;
insert into user set user='root',ssl_cipher='',x509_issuer='',x509_subject='';
flush privileges;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'mN6WT8c#' WITH GRANT OPTION; 
flush privileges;

4)此时查看新添加用户的权限

mysql> select * from mysql.user where user='root'\G;
*************************** 1. row ***************************
                  Host: localhost
                  User: root
           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
       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: *A1027271824AD76D2BBEED42D431EF9273BB492A
      password_expired: N
 password_last_changed: 2019-07-11 16:29:23
     password_lifetime: NULL
        account_locked: N
*************************** 2. row ***************************
                  Host: %
                  User: root
           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: 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: *A1F1CB851D62F002C09A0C9C4A76262473432F55
      password_expired: N
 password_last_changed: 2019-07-04 16:55:40
     password_lifetime: NULL
        account_locked: N
2 rows in set (0.00 sec)

ERROR: 
No query specified

5)重启mysql服务

cd /mysqldata/mysql/bin
[root@zjtl bin]# ./mysqladmin -uroot -p shutdown
输入密码:

或者kill Mysql进程
    
[root@zjtl /]# cd /mysqldata/mysql/bin
    
[root@zjtl bin]# ./mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值