mysql用户授权报错:1045 Access denied for user 'amp'@'%' (using password: YES)

用户amp登录后,给用户test授权,命令如下:

grant all on *.* to 'test'@'%' with grant option;

报错如下:

1 queries executed, 0 success, 1 errors, 0 warnings

查询:grant all on *.* to 'test'@'%' with grant option

错误代码: 1045
Access denied for user 'amp'@'%' (using password: YES)

执行耗时   : 0 sec
传送时间   : 0 sec
总耗时      : 0.003 sec

查找问题,发现用root用户登录后,给test授权就能OK,为什么呢?于是查看root,amp两个用户权限区别,分别执行以下两个命令:

SHOW GRANTS FOR amp;
SHOW GRANTS FOR root;

发现root用户权限如下:

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`%` WITH GRANT OPTION

amp用户权限如下:

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `amp`@`%`

最后一句DROP ROLE ON *.* TO `amp`@`%` ,注意到没有with grant option。

而with grant option表示权限传递,也就是将权限传递给第三方(其它用户)

找到原因就好办,解决办法是:

root用户登录,重新给amp用授权,命令如下:

grant all on *.* to 'amp'@'%' with grant option

然后,amp用户登录后,重新执行以下命令:

grant all on *.* to 'test'@'%' with grant option;

解决OK
 

你可能感兴趣的:(MySQL)