zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    hihocoder 1142 三分·三分求极值(三分)
    poj 3304 Segments(计算直线与线段之间的关系)
    poj 1269 Intersecting Lines(判断两直线关系,并求交点坐标)
    poj 2398 Toy Storage(计算几何 点线关系)
    poj 2318 TOYS(计算几何 点与线段的关系)
    计算几何基础(模板)
    Jmeter-基本组成
    java-面向对象
    性能测试基础
    java-多线程
  • 原文地址:https://www.cnblogs.com/djlsunshine/p/14412738.html
Copyright © 2011-2022 走看看