Академический Документы
Профессиональный Документы
Культура Документы
ADVANCED
STORED PROCEDURES
TRIGGERS
VIEWS
INDEXES
MYSQL ADMINISTRATION
FUNCTIONS
https://www.mysqltutorial.org/mysql-adminsitration/mysql-show-grants/ 1/12
04/08/2020 MySQL SHOW GRANTS Explained By Practical Examples
Summary: in this tutorial, you will learn how to use the MySQL SHOW GRANTS statement to display the
privileges and roles assigned to an account user.
The MySQL SHOW GRANTS statement returns all privileges and roles granted to an account user or role.
SHOW GRANTS
[FOR {user | role}
[USING role [, role] ...]]
In this syntax:
First, specify the name of the user account or role that you want to display the privileges that are
previously granted to the user account or role after the FOR keyword. If you skip the FOR clause,
the SHOW GRANTS returns the privileges of the current user.
Second, use the USING clause to examine the privileges associated with roles for the user. The
roles that you specify in the USING clause must previously granted to the user.
To execute the SHOW GRANTS statement, you need to have SELECT privilege for the mysql system
database, except to show privileges and roles for the current user.
Let’s take some examples of using the MySQL SHOW GRANTS statement.
A) Using MySQL SHOW GRANTS to display the privileges granted for the current
user
The following statement uses the SHOW GRANTS statement to display the privileges granted for the
current user:
SHOW GRANTS;
https://www.mysqltutorial.org/mysql-adminsitration/mysql-show-grants/ 2/12
04/08/2020 MySQL SHOW GRANTS Explained By Practical Examples
SHOW GRANTS FOR CURRENT_USER;
and
SHOW GRANTS FOR CURRENT_USER();
B) Using MySQL SHOW GRANTS to display the privileges granted for a user
CREATE DATABASE vehicles;
USE vehicles;
CREATE TABLE cars (
id INT AUTO_INCREMENT,
make VARCHAR(100) NOT NULL,
model VARCHAR(100) NOT NULL,
PRIMARY KEY (id)
);
CREATE USER musk@localhost
IDENTIFIED BY 'Super1Pass!';
https://www.mysqltutorial.org/mysql-adminsitration/mysql-show-grants/ 3/12
04/08/2020 MySQL SHOW GRANTS Explained By Practical Examples
SHOW GRANTS
FOR musk@localhost;
The GRANT USAGE is the synonym of no privilege. By default, when a new user created, it has no
privilege.
Sixth, grant all privileges on the vehicles database to the user musk@localhost :
GRANT ALL
ON vehicles.*
TO musk@localhost;
https://www.mysqltutorial.org/mysql-adminsitration/mysql-show-grants/ 4/12
04/08/2020 MySQL SHOW GRANTS Explained By Practical Examples
SHOW GRANTS
FOR musk@localhost;
C) Using MySQL SHOW GRANTS to display the privileges granted for a role
CREATE ROLE writer@localhost;
SHOW GRANTS
FOR writer@localhost;
https://www.mysqltutorial.org/mysql-adminsitration/mysql-show-grants/ 5/12
04/08/2020 MySQL SHOW GRANTS Explained By Practical Examples
Third, grant SELECT , INSERT , UPDATE , and DELETE privileges on the vehicles database to the
writer@localhost :
GRANT
SELECT,
INSERT,
UPDATE,
DELETE
ON vehicles.*
TO writer@localhost;
SHOW GRANTS
FOR writer@localhost;
https://www.mysqltutorial.org/mysql-adminsitration/mysql-show-grants/ 6/12
04/08/2020 MySQL SHOW GRANTS Explained By Practical Examples
CREATE USER jame@localhost
IDENTIFIED BY 'Secret@Pass1';
GRANT EXECUTE
ON vehicles.*
TO jame@localhost;
GRANT writer@localhost
TO jame@localhost;
https://www.mysqltutorial.org/mysql-adminsitration/mysql-show-grants/ 7/12
04/08/2020 MySQL SHOW GRANTS Explained By Practical Examples
SHOW GRANTS
FOR jame@localhost;
Finally, use the USING clause in the SHOW GRANTS statement to display privileges associated with the
writer@localhost role:
SHOW GRANTS
FOR jame@localhost
USING writer@localhost;
https://www.mysqltutorial.org/mysql-adminsitration/mysql-show-grants/ 8/12
04/08/2020 MySQL SHOW GRANTS Explained By Practical Examples
In this tutorial, you have learned how to use the MySQL SHOW GRANTS statement to display privileges
granted for an account user or role.
Yes No
ADVERTISEMENT
Previous
MySQL GRANT
Next
MySQL REVOKE
What Is MySQL?
https://www.mysqltutorial.org/mysql-adminsitration/mysql-show-grants/ 9/12
04/08/2020 MySQL SHOW GRANTS Explained By Practical Examples
ADVERTISEMENT
USER MANAGEMENTS
Create Users
Grant Privileges
Revoke Privileges
Manage Roles
Show Privileges
Drop Users
Change Passwords
ADVERTISEMENT
MySQL Backup
MySQL Restore
DATABASE MAINTENANCE
https://www.mysqltutorial.org/mysql-adminsitration/mysql-show-grants/ 10/12
04/08/2020 MySQL SHOW GRANTS Explained By Practical Examples
SHOW COMMANDS
Show Databases
Show Tables
Show Columns
Show ProcessList
ADVERTISEMENT
https://www.mysqltutorial.org/mysql-adminsitration/mysql-show-grants/ 11/12
04/08/2020 MySQL SHOW GRANTS Explained By Practical Examples
SITE LINKS
About Us
Contact Us
Request a Tutorial
Privacy Policy
Donations
https://www.mysqltutorial.org/mysql-adminsitration/mysql-show-grants/ 12/12