跳过授权表登录后使用replace into创建root权限用户
admin
2023-05-03 10:04:23
0次

    起因:

    刚刚搭建好的mysql数据库,做基础优化时,不小心把所有用户都删除了,并且退出了。没办法,只好跳过授权表登录,新建root用户。

    过程如下:


一、停掉mysql,跳过授权登录

    [root@explnk-zabbix zabbix-2.2.9]# /etc/init.d/mysqld stop

    Shutting down MySQL... SUCCESS! 

    [root@explnk-zabbix zabbix-2.2.9]# mysqld_safe --skip-grant-table &

    [1] 30178

    [root@explnk-zabbix zabbix-2.2.9]# 160418 10:49:54 mysqld_safe Logging to '/application/mysql/data/explnk-zabbix.err'.

    160418 10:49:54 mysqld_safe Starting mysqld daemon with databases from /application/mysql/data

    

    [root@explnk-zabbix zabbix-2.2.9]# mysql

    Welcome to the MySQL monitor.  Commands end with ; or \g.

    Your MySQL connection id is 1

    Server version: 5.5.32 MySQL Community Server (GPL)

    

    Copyright (c) 2000, 2013, 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>


二、创建拥有root权限的用户

  2.1 错误例子:

    这里最开始遇到个坑,使用insert into创建的用户没有任何权限,登录之后无法进行操作,语句如下:

    INSERT INTO user (Host,User,Password) VALUES('localhost','root',PASSWORD('biscuit'));

    *************************** 2. row ***************************

                      Host: localhost

                      User: root

                  Password: *7495041D24E489A0096DCFA036B166446FDDD992

               Select_priv: N

               Insert_priv: N

               Update_priv: N

               Delete_priv: N

               Create_priv: N

                 Drop_priv: N

               Reload_priv: N

             Shutdown_priv: N

              Process_priv: N

                 File_priv: N

                Grant_priv: N

           References_priv: N

                Index_priv: N

                Alter_priv: N

              Show_db_priv: N

                Super_priv: N

     Create_tmp_table_priv: N

          Lock_tables_priv: N

              Execute_priv: N

           Repl_slave_priv: N

          Repl_client_priv: N

          Create_view_priv: N

            Show_view_priv: N

       Create_routine_priv: N

        Alter_routine_priv: N

          Create_user_priv: N

                Event_priv: N

              Trigger_priv: N

    Create_tablespace_priv: N

                  ssl_type: 

                ssl_cipher: 

               x509_issuer: 

              x509_subject: 

             max_questions: 0

               max_updates: 0

           max_connections: 0

      max_user_connections: 0

                    plugin: 

     authentication_string: NULL



  2.2 正确方法1:

    mysql> use mysql

    Database changed

    mysql> insert into user (Select_priv,           Insert_priv,           Update_priv,           Delete_priv,           Create_priv,             Drop_priv,           Reload_priv,         Shutdown_priv,          Process_priv,             File_priv,            Grant_priv,       References_priv,            Index_priv,            Alter_priv,          Show_db_priv,            Super_priv, Create_tmp_table_priv,      Lock_tables_priv,          Execute_priv,       Repl_slave_priv,      Repl_client_priv,      Create_view_priv,        Show_view_priv,   Create_routine_priv,    Alter_routine_priv,      Create_user_priv,            Event_priv,          Trigger_priv,Create_tablespace_priv,User,Password) values ( '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','gl','gl');    

    Query OK, 1 row affected, 3 warnings (0.06 sec)

    

    mysql> update user set password=PASSWORD('explink') where user='gl';

    Query OK, 1 row affected (0.08 sec)

    Rows matched: 1  Changed: 1  Warnings: 0


  2.3 正确方法2:

    跳过授权表登录后是无法使用grant建立用户的,报错如下:

    mysql> grant all privileges on *.* to liang@'localhost' identified by '123456' with grant option;    

    ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement


    解决办法:

    只要刷新一下用户权限即可

    mysql> flush privileges;

    Query OK, 0 rows affected (0.00 sec)

    

    mysql> grant all privileges on *.* to liang@'localhost' identified by '123456' with grant option;

    Query OK, 0 rows affected (0.00 sec)



三、退出登录并重新启动mysql

    [root@explnk-zabbix zabbix-2.2.9]# /etc/init.d/mysqld stop

    [root@explnk-zabbix zabbix-2.2.9]# /etc/init.d/mysqld start


四、登录mysql查看权限


    [root@explnk-zabbix zabbix-2.2.9]# mysql -ugl -p           

    Enter password: 

    Welcome to the MySQL monitor.  Commands end with ; or \g.

    Your MySQL connection id is 1

    Server version: 5.5.32 MySQL Community Server (GPL)

    

    Copyright (c) 2000, 2013, 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> select * from mysql.user\G


    *************************** 3. row ***************************

                      Host: 

                      User: gl

                  Password: *5F70B50879BD3B98CB5A945D3A6A7C92F41B8AE8

               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: 

     authentication_string: NULL

    3 rows in set (0.00 sec)


六、perfect
    

    参考blog:http://my.oschina.net/leejun2005/blog/76140

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...