Quantcast
Channel: SQLParty »大数据
Viewing all articles
Browse latest Browse all 5

MySQL information_schema中索引信息查询

$
0
0

show index无疑可以针对单表查询详细的索引信息,但是批量检查索引使用批处理show index就不太方便了。MySQL也支持从系统表(information_schema)下查询索引信息,但是略显隐晦,记录如下。

一、通用方式

information_schema.STATISTICS表提供了索引相关的信息。

以下两个命令等价:

SELECT * FROM INFORMATION_SCHEMA.STATISTICS
WHERE table_name = ‘tbl_name’
AND table_schema = ‘db_name’

SHOW INDEX
FROM tbl_name
FROM db_name

二、Innodb 引擎表

MySQL 5.6之后,innodb引擎的表,其有独立的内部表,如INNODB_SYS_TABLES, INNODB_SYS_INDEXES, and INNODB_SYS_FIELDS 。

示例:查询表名、索引名、以及索引列信息,可以:

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,
information_schema.innodb_sys_indexes i,
information_schema.innodb_sys_fields f
WHERE t.table_id=i.table_id
and i.index_id = f.INDEX_ID
GROUP BY 1,2;

 

参考:

http://blog.9minutesnooze.com/mysql-information-schema-indexes/

 

The post MySQL information_schema中索引信息查询 appeared first on SQLParty.


Viewing all articles
Browse latest Browse all 5

Trending Articles