如何查看我的数据库是否有索引?
如果是特定的桌子呢?
如何查看我的数据库是否有索引?
如果是特定的桌子呢?
当前回答
select
table_name,
index_name,
seq_in_index,
column_name,
non_unique,
index_type,
comment
from
information_schema.statistics
where 1=1
and table_schema = 'my_schema'
and table_name = 'my_table'
order by 1,2,3,4,5,6
其他回答
查询数据库中所有已禁用的索引
SELECT INDEX_SCHEMA, COLUMN_NAME, COMMENT
FROM information_schema.statistics
WHERE table_schema = 'mydb'
AND COMMENT = 'disabled'
如果你想一次性查看所有数据库的所有索引:
use information_schema;
SELECT * FROM statistics;
如果我们知道下面的索引名,我们可以直接看到表上的索引:
Select * from all_indexes where index_name= 'your index'
您可以使用此查询来获取指定数据库中每个表的索引名和索引号。
SELECT TABLE_NAME,
COUNT(1) index_count,
GROUP_CONCAT(DISTINCT(index_name) SEPARATOR ',\n ') indexes
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = 'mydb'
AND INDEX_NAME != 'primary'
GROUP BY TABLE_NAME
ORDER BY COUNT(1) DESC;
在我的例子中,这适用于在对应的表中获取索引字段的表名和列名。
SELECT TABLE_NAME , COLUMN_NAME, COMMENT
FROM information_schema.statistics
WHERE table_schema = 'database_name';