目录
2.2、查询某个数据库(table_schema)的全部表索引,可以从INFORMATION_SCHEMA架构中的STATISTICS表中获取索引信息
3、查看一台主机所有数据库的所有索引信息,则可以通过INFORMATION_SCHEMA查看
1、问题引入
MySQL数据库之中,如何查看一个数据库是否有索引,有哪些索引?又如何查看一张指定的数据表的索引信息呢?
2、查看一张指定表的索引信息
2.1 、查看指定数据库之中某一张表名的索引信息
show index from tablename;
2.2、查询某个数据库(table_schema)的全部表索引,可以从INFORMATION_SCHEMA
架构中的STATISTICS
表中获取索引信息
select distinct
table_name,
index_name
from
information_schema.statistics
where
table_schema = 'pay(数据库名称)';
3、查看一台主机所有数据库的所有索引信息,则可以通过INFORMATION_SCHEMA
查看
use information_schema;
select * from statistics;
4、获取指定数据库中索引的编号以及每个表的索引名
select table_name,
count(1) index_count,
group_concat(distinct(index_name) separator ',\n ') indexes
from information_schema.statistics
where table_schema = 'pay'
and index_name != 'primary'
group by table_name
order by count(1) desc;
5、查询出只包含索引的结果集
select distinct s.*
from information_schema.statistics s
left outer join information_schema.table_constraints t
on t.table_schema = s.table_schema
and t.table_name = s.table_name
and s.index_name = t.constraint_name
where 0 = 0
and t.constraint_name is null
and s.table_schema = 'pay';