[解决] Error Code: 1044. Access denied for user 'root'@'%' to database

Posted 代立冬

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[解决] Error Code: 1044. Access denied for user 'root'@'%' to database相关的知识,希望对你有一定的参考价值。

今天在测试集群用的mysql上,遇到个权限的问题:

SQLException : SQL state: 42000 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'root'@'%' to database 'ranger' ErrorCode: 1044

我是以root用户登录mysql的,怎么还会遇到这问题呢,有点猫腻,我查看了下mysql下user表的各用户的权限信息

mysql> SELECT host,user,password,Grant_priv,Super_priv FROM mysql.user;
+--------------+---------+-------------------------------------------+------------+------------+
| host         | user    | password                                  | Grant_priv | Super_priv |
+--------------+---------+-------------------------------------------+------------+------------+
| 192.168.28.% | oozie   | *FED29C14B2E900D70B11B1F1B370F953BA51A6A0 | N          | Y          |
| 192.168.28.% | hive    | *FED29C14B2E900D70B11B1F1B370F953BA51A6A0 | N          | Y          |
| 192.168.28.% | root    | *FED29C14B2E900D70B11B1F1B370F953BA51A6A0 | Y          | Y          |
| localhost    | ranger  | *84BB87F6BF7F61703B24CE1C9AA9C0E3F2286900 | N          | N          |
| localhost    | root    | 0                                         | Y          | Y          |
| %            | root    | *FED29C14B2E900D70B11B1F1B370F953BA51A6A0 | N          | Y          |
| 127.0.0.1    | root    | *FED29C14B2E900D70B11B1F1B370F953BA51A6A0 | Y          | Y          |
| %            | ranger  | *84BB87F6BF7F61703B24CE1C9AA9C0E3F2286900 | N          | Y          |
+--------------+---------+-------------------------------------------+------------+------------+

可以看到授权的权限没有打开: Grant_priv is set to N for root@%. 修复下

UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';
FLUSH PRIVILEGES;

重新登录下,就ok了。如果不能执行update的话,那就先停下mysql服务,然后mysqld_safe --skip-grant-table & (这个可以参考之前文章:http://blog.csdn.net/oDaiLiDong/article/details/50196661),等改完之后再正常启动mysql


以上是关于[解决] Error Code: 1044. Access denied for user 'root'@'%' to database的主要内容,如果未能解决你的问题,请参考以下文章

mysql拒绝访问 Error 1044/1045 问题的解决

[故障解决]Mysql爆出ERROR 1044 (42000)的错误怎么办?

解决 ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql&

mysql 数据库出现 ERROR 1044 (42000)

mysql ERROR 1044 (42000): Access denied for user ''@'localhost' to database

ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'mysql