mysql ERROR 1044 (42000): Access denied for user 'root'@'127.0.0.1'

本文详细解析了在禅道系统安装过程中遇到的“ERROR1044(42000)”错误,深入探讨了该错误与MySQL中root用户权限的关系,特别是WITH GRANT OPTION选项的重要性,并提供了具体的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在安装禅道系统的时候创建账号时遇到了“ERROR 1044 (42000): Access denied for user 'root'@'127.0.0.1' to database zentao”错误。

mysql -uroot -p

登陆mysql,执行语句:

mysql> select current_user() from dual;

+----------------+

| current_user() |

+----------------+

| root@localhost |

+----------------+

1 row in set (0.00 sec

 

mysql> select host,user from user where user='root';

+-----------+----------+

| host      | user     |

+-----------+----------+

| %         | root     |

| 127.0.0.1 | root     |

| ::1       | root     |

| localhost | root     |

+-----------+----------+

7 rows in set (0.00 sec)

 

mysql>  show grants for root@'localhost';

+--------------------------------------------------------------+

| Grants for root@localhost                                    |

+--------------------------------------------------------------+

| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost'            |

| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |

+--------------------------------------------------------------+

2 rows in set (0.00 sec)

 

mysql> show grants for root@'127.0.0.1';

+---------------------------------------------------------------------+

| Grants for root@127.0.0.1                                           |

+---------------------------------------------------------------------+

1 row in set (0.00 sec)

 

mysql> show grants for root@'%';

+-------------------------------------------+

| Grants for root@%                         |

+-------------------------------------------+

| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' |

+-------------------------------------------+

1 row in set (0.00 sec)

 

    如上所示,root@localhost账号没有WITH GRANT OPTION选项,关于WITH GRANT OPTION选项,如果想让授权的用户,也可以将这些权限授予给其他用户,需要选项 “WITH GRANT OPTION“ 。也就是说有这个选项就可以将权限传递给第三方。这也是上面root@localhost用户给其它用后授权报错的原因,如果以 root@127.0.0.1登录(此账号拥有WITHGRANT OPTION选项),创建用户并授权就不会有这个错误,如下所示:

 

mysql>  grant all on *.* to root@'127.0.0.1' identified by 'test';

mysql> flush privileges;

 

 原文链接:http://www.cnblogs.com/kerrycode/archive/2018/06/19/9198566.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值