简体   繁体   English

是否有查询以了解是否已为 mysql 用户授予特定权限?

[英]Is there a query to know if a particular privilege has been granted for a mysql user?

I know SHOW GRANTS can be used to find all privileges for a particular user but what if I just wanted to know if the current user has lets say RELOAD privileges?我知道SHOW GRANTS可用于查找特定用户的所有权限,但如果我只想知道当前用户是否拥有RELOAD权限呢? is there a query for that, that will simply return true/false?是否有一个查询,它只会返回真/假? or is parsing the string result from SHOW GRANTS FOR CURRENT USER the only way?还是从SHOW GRANTS FOR CURRENT USER解析字符串结果是唯一的方法?

Test测试

SELECT Reload_priv 
FROM mysql.user 
WHERE user = SUBSTRING_INDEX(USER(), '@', 1) COLLATE utf8_general_ci
  AND host = SUBSTRING_INDEX(USER(), '@', -1) COLLATE utf8_general_ci;

Will work only when the user in mysql.user is specified with definite host (ie any pattern/mask is not used).仅当mysql.user中的用户指定了明确的主机(即不使用任何模式/掩码)时才有效。 Ie if user foo is authenticated as foo@localhost using foo@% value in mysql.user then none row will be found.即,如果用户foo使用mysql.user中的foo@%值验证为foo@localhost ,则将找不到任何行。

Adjust collation if needed.如果需要,调整排序规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM