Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View grants in MySQL

Tags:

mysql

How do I view the grants (access rights) for a given user in MySQL?

like image 749
alanc10n Avatar asked Sep 24 '08 14:09

alanc10n


People also ask

How do I find grants on my table?

To determine which users have direct grant access to a table we'll use the DBA_TAB_PRIVS view: SELECT * FROM DBA_TAB_PRIVS; You can check the official documentation for more information about the columns returned from this query, but the critical columns are: GRANTEE is the name of the user with granted access.

Where are grants stored in MySQL?

Information about account privileges is stored in the grant tables in the mysql system database. For a description of the structure and contents of these tables, see Section 6.2. 3, “Grant Tables”.

What are grants in MySQL?

The WITH GRANT OPTION clause gives the user the ability to give to other users any privileges the user has at the specified privilege level. To grant the GRANT OPTION privilege to an account without otherwise changing its privileges, do this: GRANT USAGE ON *.

What is grant usage on * * in MySQL?

The GRANT statement grants privileges to MySQL user accounts. GRANT also serves to specify other account characteristics such as use of secure connections and limits on access to server resources.


5 Answers

An alternative method for recent versions of MySQL is:

select * from information_schema.user_privileges where grantee like "'user'%";

The possible advantage with this format is the increased flexibility to check "user's" grants from any host (assuming consistent user names) or to check for specific privileges with additional conditions (eg, privilege_type = 'delete').

This version is probably better suited to use within a script while the "show grants" syntax is better for interactive sessions (more "human readable").

like image 120
igelkott Avatar answered Oct 19 '22 10:10

igelkott


mysql> show grants for 'user'@'host'
like image 25
alanc10n Avatar answered Oct 19 '22 10:10

alanc10n


You could try this:

SELECT GRANTEE, PRIVILEGE_TYPE FROM information_schema.user_privileges;
SELECT User,Host,Db FROM mysql.db;
like image 26
Anita Avatar answered Oct 19 '22 09:10

Anita


You might want to check out mk-show-grants from Maatkit, which will output the current set of grants for all users in a canonical form, making version control or replication more straightforward.

like image 23
Jon Topper Avatar answered Oct 19 '22 08:10

Jon Topper


If you're already running a web server with PHP then phpMyAdmin is a fairly friendly administrative tool.

like image 1
Kevin ORourke Avatar answered Oct 19 '22 10:10

Kevin ORourke