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

  • 相关阅读:
    lambda函数
    linux 自学系列:wc命令
    linux 自学系列:chmod 权限操作
    linux 自学系列:创建、删除目录、移动、更名文件或目录
    linux 自学系列:vi、vim编辑工具
    《架构之美》学习随笔:设计第一步
    安装memcache 时提示error while loading shared libraries: libevent2.0解决办法
    《架构之美》学习随笔:保证质量
    linux 自学系列:环境变量设置
    logging模块学习笔记:logger 对象、日志等级
  • 原文地址:https://www.cnblogs.com/djlsunshine/p/14412738.html
Copyright © 2011-2022 走看看