mysql 查询索引

information_schema数据库是MySQL自带的,它提供了访问数据库元数据的方式。

SELECT
    INDEX_SCHEMA,
    TABLE_NAME,
    index_name,
    group_concat(column_name order by seq_in_index) -- 列合并
FROM
    information_schema.statistics -- 提供了关于表索引的信息。是show index from schemaname.tablename的结果取之此表。
WHERE
    table_schema = 'test'
    AND table_name in (select
                          table_name
                       from information_schema.TABLES -- 提供了关于数据库中的表的信息(包括视图)。是show tables from schemaname的结果取之此表。
                       where TABLE_SCHEMA = 'test')
    and index_name like 'idx%'
group by INDEX_SCHEMA , TABLE_NAME , INDEX_NAME

posted on 2015-03-24 17:10  碎星斩月  阅读(183)  评论(0)    收藏  举报

导航