“show databases” shows all databases where you (logged in user) have some privileges.
Is there a way to show all databases where user “xxx” has some privileges?
Edit:
I have an user “mickey”:
mysql> show grants for mickey;
+-------------------------------------------------------------------------------------------------------+
| Grants for mickey@% |
+-------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'mickey'@'%' IDENTIFIED BY PASSWORD '*B9E506CBC9D7D8352A3C02DBC94677A5DEF491B8' |
| GRANT ALL PRIVILEGES ON `mickey\_%`.* TO 'mickey'@'%' |
+-------------------------------------------------------------------------------------------------------+
User mickey is allowed to create/drop databases and tables with name “mickey_%”. Filtering out these databases is easy but only because his databases have prefix “mickey_”.
there is one databases called “mickey_example2” where mickey has all privileges. I am not able to find this database in information_schema or mysql db.
And this ist the only information about ‘mickey’ in information_schema.USER_PRIVILEGES:
mysql> SELECT * FROM information_schema.USER_PRIVILEGES WHERE GRANTEE LIKE '%mickey%';
+--------------+---------------+----------------+--------------+
| GRANTEE | TABLE_CATALOG | PRIVILEGE_TYPE | IS_GRANTABLE |
+--------------+---------------+----------------+--------------+
| 'mickey'@'%' | def | USAGE | NO |
+--------------+---------------+----------------+--------------+
MySql manual says:
MySQL implements databases as directories in the data directory, so
this statement simply lists directories in that location. However, the
output may include names of directories that do not correspond to
actual databases.
which means to me that there does not have to be any information (about existing databases) avaiable in information_schema, especially if the database is empty.
After a lot of searching and reading I found out that there is no nice and clean way to find “show databases” for other users.
I have changed my db design by doing following:
– every database name begins with $username_
– $username cannot contain underline “_”
and I have a user without any grants except “SHOW DATABASES” and I found user’s databases using WHERE LIKE with SHOW DATABASES command:
and ? is replaced with: