Skip to content
Advertisement

mysql get all table privileges for a user

I have the following query that I run against a postgresql DB whose intent is to return all the tables in a given schema for which the user does NOT have SELECT privileges

How would I construct a similar query for use against a mysql database? mysql doesn’t have a has_table_privilege() function

Advertisement

Answer

This will work in MySQL:

A table is not visible to your user, i.e., it doesn’t even show up as a row in information_schema.tables, if you don’t have SELECT privilege on the table.

But the more general answer is how can one get a list of tables that are visible to some other arbitrary user, assuming one is querying from a superuser session and can see all tables.

For that, you’d have to join to the privileges tables mysql.user, mysql.db, and mysql.tables_priv:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement