zoukankan      html  css  js  c++  java
  • ERROR 1044 (42000): Access denied for user 'root'@'localhost'

    同事反馈一台 MySQL5.6 创建用户无法授权,提示[ERROR 1044 (42000): Access denied for user 'root'@'localhost'] 。如下所示:

    mysql> grant all on xxx.* to xxx@'localhost' identified by 'xxx';
    ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'xxxx'
    mysql> 
    

    root用户应该不会权限才对。查看一下权限

    [root@localhost][mysql]> select current_user() from dual;
    +----------------+
    | current_user() |
    +----------------+
    | root@localhost |
    +----------------+
    1 row in set (0.00 sec)
    
    [root@localhost][mysql]> select host,user from user where user='root';
    +-----------+------+
    | host      | user |
    +-----------+------+
    | %         | root |
    | localhost | root |
    +-----------+------+
    2 rows in set (0.00 sec)
    
    [root@localhost][mysql]> show grants for root;
    +--------------------------------------------------------------------------------------------------------------------------------+
    | Grants for root@%                                                                                                              |
    +--------------------------------------------------------------------------------------------------------------------------------+
    | GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' WITH GRANT OPTION |
    +--------------------------------------------------------------------------------------------------------------------------------+
    1 row in set (0.00 sec)
    

    看着没什么问题。只能看下Grant_priv权限了。

    [root@localhost][mysql]> SELECT host,user,password,Grant_priv,Super_priv FROM mysql.user;
    +-----------+---------+-------------------------------------------+------------+------------+
    | host      | user    | password                                  | Grant_priv | Super_priv |
    +-----------+---------+-------------------------------------------+------------+------------+
    | %         | root    | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | N          | Y          |
    +-----------+---------+-------------------------------------------+------------+------------+
    1 rows in set (0.00 sec)
    

    发现 grant_priv 权限为N,也就是说root用户不能授权给其他用户,改为Y试一下

    [root@localhost][mysql]> UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';
    [root@localhost][mysql]> FLUSH PRIVILEGES;
    

    再次尝试添加用户,没问题了。

    mysql>  grant all on xxx.* to xxx@'192.168.%' identified by 'test1249';
    Query OK, 0 rows affected, 1 warning (0.00 sec)
     
     
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    
  • 相关阅读:
    正则表达式
    浏览器 User-Agent 大全
    python3爬虫开发实战 第六课 爬虫基本流程
    python3爬虫开发实战 第五课 常用库的安装
    python3爬虫开发实战 第四课 MySQL
    python3爬虫开发实战 第三课 Redis数据库
    python3爬虫开发实战 第二课 MongoDB安装
    python3爬虫开发实战 第一课 python安装和Pycharm安装
    批处理——数据库
    Aop所需包
  • 原文地址:https://www.cnblogs.com/fsckzy/p/11290337.html
Copyright © 2011-2022 走看看