SHOW GRANTS - MySQL


SHOW GRANTS

Overview
The SHOW GRANTS command in MySQL retrieves information about the privileges granted to a specific user or role. It provides an overview of the permissions, roles, and privileges assigned to a database user, making it useful for auditing user privileges, troubleshooting access issues, and maintaining a secure database environment.

Syntax

SHOW GRANTS [FOR user_name]

Options

  • FOR user_name: Limits the result to the grants for a specific user.

Examples

  • Show all grants for the user ‘test_user’:
SHOW GRANTS FOR test_user;
  • Display grants for all users:
SHOW GRANTS;

Common Issues

  • Permission denied: Ensure the current user has sufficient privileges to view grants for the specified user.
  • Blank results: The user may not have any grants assigned. Additionally, check for any filtering options that may limit the results.

Integration
SHOW GRANTS can be combined with other MySQL commands for advanced tasks:

  • Revoke permissions: REVOKE ... FROM user_name
  • Grant additional permissions: GRANT ... TO user_name
  • Create a new user: CREATE USER user_name

Related Commands

  • SHOW USERS: Displays a list of database users.
  • REVOKE: Revokes privileges from a user or role.
  • GRANT: Grants privileges to a user or role.