如何查看我的数据库是否有索引?
如果是特定的桌子呢?
如何查看我的数据库是否有索引?
如果是特定的桌子呢?
当前回答
按顺序获取一列中每个索引的所有索引列。
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 = 'sakila'
GROUP BY 1,2;
裁判:http://blog.9minutesnooze.com/mysql-information-schema-indexes/
其他回答
查询数据库中所有已禁用的索引
SELECT INDEX_SCHEMA, COLUMN_NAME, COMMENT
FROM information_schema.statistics
WHERE table_schema = 'mydb'
AND COMMENT = 'disabled'
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
SHOW INDEX FROM mytable FROM mydb;
SHOW INDEX FROM mydb.mytable;
见文档。
为什么不显示创建表myTable ?
有人告诉过我,但我没看到有人提到,有什么不好的吗?
如果您只想看一下索引和列信息,那就很简单了。
如果你想一次性查看所有数据库的所有索引:
use information_schema;
SELECT * FROM statistics;