Accessing user metadata
If you write a program that interacts with MySQL dynamically, it will need to adopt its behavior based on the server setup and the characteristic of a user's account. You will then need to be able to access what privileges have been granted to a user from within a MySQL session; you obviously cannot count on having administrator access. For this reason, MySQL provides access to user information from within a session.
SHOW GRANTS
In using SHOW GRANTS
, we ask MySQL to return the GRANT
statements used to grant privileges to the user. The results will show the precise tables for which permission has been granted. However, any passwords that were part of the original GRANT
statement are returned as a hash.
As a user mammamia
, we can see the GRANT
statements that pertain to that account as shown below:
mysql> SHOW GRANTS; +-----------------------------------------------------------------------------------------------------------------+ | Grants for mammamia@localhost| ...