• Linux下Mysql root用户失去特权怎么办


    问题如下:

    [root@localhost ~]# mysql -uroot -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 8
    Server version: 8.0.20 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2020, 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>
    mysql> use mysql;
    ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'mysql'
    mysql>
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    +--------------------+
    1 row in set (0.01 sec)
    
    mysql>

    解决办法:

    1、编辑MySQL配置文件

    # vi /etc/my.cnf

    添加skip-grant-tables

    2、重启MySQL服务

    # systemctl restart mysqld

    3、进入MySQL免认证模式

    [root@localhost ~]# mysql -u root -p
    Enter password:        直接敲回车
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 7
    Server version: 8.0.20 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2020, 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>    

    4、输入以下代码恢复超级权限

    mysql> use mysql;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> update user set Update_priv='Y' where user='root';
    Query OK, 1 row affected (0.06 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql>
    mysql> update user set Grant_priv='Y' where user='root';
    Query OK, 1 row affected (0.10 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql> exit
    Bye

    5、恢复

    # vi /etc/my.cnf

    去除skip-grant-tables

    重启

    # systemctl restart mysqld

  • 相关阅读:
    python判断语句和循环语句
    Web项目如何做单元测试
    PHP接口自动化测试框架实现
    引入缺陷的原因都有哪些?
    测试基础:(一)
    测试基础(二)
    测试术语2
    测试术语3
    测试术语4
    Spring Cloud Stream与Spring Cloud Bus区别?
  • 原文地址:https://www.cnblogs.com/djlsunshine/p/14412738.html
Copyright © 2020-2023  润新知