SELECT t.name AS 'Table',
i.name AS 'Index',
GROUP_CONCAT(f.name ORDER BY f.pos) AS 'Columns'
FROM information_schema.innodb_sys_tables t
JOIN information_schema.innodb_sys_indexes i USING (table_id)
JOIN information_schema.innodb_sys_fields f USING (index_id)
-- WHERE t.schema = 'mysql'
GROUP BY 1,2;
对于mysql 5.6之前的版本:
SELECT TABLE_NAME AS `Table`,
index_name AS `Index`,
GROUP_CONCAT(column_name ORDER BY seq_in_index) AS `Columns`
FROM information_schema.statistics
WHERE table_schema = 'db02'
GROUP BY 1,2;
速度略慢。