MySQL database for users

Does anyone know the mySQL syntax to show the database names that the user has the privilege to view in the mySQL database? Say that the user "dimitris" accesses the database in "localhost", which syntax should all the databases that he has to select, update, insert, etc. see.

Dimitris

+6
mysql
source share
2 answers

You can get a list of the databases available to you:

SHOW DATABASES; 

If you want to get a list for a user other than the user with whom you are logged in, you need to query the mysql.db table.

+3
source share

For the current registered user, you can use SHOW DATABASES; . But if the user has the SHOW DATABASES; privilege SHOW DATABASES; , he will be able to see all the databases, even if he does not have access to it. ( link )

Assuming you read access to the mysql.db table, you can use:

 SELECT * FROM mysql.db WHERE User="dimitris"; 

This will return the result set with Host (e.g. localhost ), Db (e.g. somedatabase ), User (e.g. dimitris ) and privileges for this database ( Select_priv , Update_priv , etc.)

+9
source share

All Articles