简体   繁体   中英

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? 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?

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). Ie if user foo is authenticated as foo@localhost using foo@% value in mysql.user then none row will be found.

Adjust collation if needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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