
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to display grant defined for a MySQL user?
Use SHOW GRANTS for this. Following is the syntax −
SHOW GRANTS FOR 'yourUserName'@'yourHostName';
Let us display the user name and host name from MySQL.user table.
mysql> select user,host from MySQL.user;
This will produce the following output −
+------------------+-----------+ | user | host | +------------------+-----------+ | Bob | % | | Charlie | % | | Robert | % | | User2 | % | | mysql.infoschema | % | | mysql.session | % | | mysql.sys | % | | root | % | | @UserName@ | localhost | | Adam Smith | localhost | | Chris | localhost | | David | localhost | | James | localhost | | John | localhost | | John Doe | localhost | | User1 | localhost | | am | localhost | | hbstudent | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | +------------------+-----------+ 20 rows in set (0.00 sec)
Let use SHOW GRANTS to display grant for a specific user −
mysql> SHOW GRANTS FOR 'Robert'@'%
This will produce the following output −
+----------------------------------------------------------------------+ | Grants for Robert@% | +----------------------------------------------------------------------+ | GRANT USAGE ON *.* TO `Robert`@`%` | | GRANT ALL PRIVILEGES ON `sample`.* TO `Robert`@`%` WITH GRANT OPTION | | GRANT EXECUTE ON `web`.* TO `Robert`@`%` | +----------------------------------------------------------------------+ 3 rows in set (0.05 sec)
Above, the SHOW GRANTS example returns the grant information for the user Robert on the host, which MySQL assumes '%'.
- Related Articles
- How can we grant privileges to a MySQL user?
- Grant all privileges of a database to a MySQL user?
- Grant a user permission to only view a MySQL view?
- MySQL query to create user and grant permission
- How can we grant a user to access all stored procedures in MySQL?
- How Can we permanently define user-defined variable for a client in MySQL?
- Display all grants for user in MySQL
- Using User-Defined Variables in MySQL
- Select into a user-defined variable with MySQL
- How can we set up a MySQL User account by using SQL GRANT statement?
- Add user defined value to a column in a MySQL query?
- Perform MySQL SELECT INTO user-defined variable
- In MySQL, why a client cannot use a user-defined variable defined by another client?
- User-defined variables vs Local Variables in MySQL?
- System variables vs User-defined variables in MySQL?

Advertisements