information_schema.tables はアクセス可能なものだけを返してくれるので、そのまま検索する。
SELECT *
FROM information_schema.tables;
SELECT *
FROM information_schema.tables
WHERE table_schema NOT IN ('mysql', 'information_schema', 'performance_schema');
mysql.tablesにテーブル名と、保有する権限名が格納されているが、 グローバル・レベルで付与された権限、DBレベルで付与された権限は含まれないため、 information_schema.tables, mysql.user, mysql.db, mysql.tables_privから必要な情報を取得し絞り込む。
SELECT table_schema,
table_name,
table_comment
FROM
(SELECT it.table_schema,
it.table_name,
it.table_comment,
(select select_priv
from mysql.user mu
where mu.user = 'カレント・ユーザー名'
and mu.host = 'ホスト名') as g_level,
(select select_priv
from mysql.db md
where md.user = 'カレント・ユーザー名'
and md.host = 'ホスト名'
and md.db = it.table_schema) as db_level,
(select table_priv
from mysql.tables_priv mt
where mt.user = 'カレント・ユーザー名'
and mt.host = 'ホスト名'
and mt.table_priv = 'Select'
and mt.table_name = it.table_name) as t_level
FROM information_schema.tables it
WHERE it.table_schema NOT IN('information_schema', 'mysql', 'performance_schema')) all_tables
WHERE g_level = 'Y'
OR db_level = 'Y'
OR t_level = 'Select';
カレント・ユーザー名
: 現在のセッションのユーザー名
ホスト名
: 現在のセッションのホスト名
mt.table_priv='Select'
SELECT select_priv
t_level = 'Select'
: 探したい権限に合わせる