mysql查看索引大小

发布时间: 2023-11-21 11:01 阅读: 文章来源:1MUMB728PS

表:information_schema.TABLES

information_schema.tables存储了数据表的元数据信息,下面对常用的字段进行介绍:

table_schema: 记录数据库名;table_name: 记录数据表名;Table_type: 表类型:视图、基础表engine : 存储引擎;table_rows: 关于表的粗略行估计;data_length : 记录表的大小(单位字节);index_length : 记录表的索引的大小;row_format: 可以查看数据表是否压缩过;

-- 数据容量, 索引容量

select sum(DATA_LENGTH), sum(INDEX_LENGTH)FROM information_schema.TABLES;

-- 查询各个库的容量

select table_schema AS "数据库",sum(table_rows) as "记录数",sum(truncate(data_length/1024/1024, 2)) as "数据容量(MB)",sum(truncate(index_length/1024/1024, 2)) as "索引容量(MB)"from information_schema.tablesgroup by table_schemaorder by sum(data_length) desc, sum(index_length) DESC;

-- 查看某个库的容量

select data_length, concat(round(sum(data_length/1024/1024),2),"MB") as DATAfrom information_schema.tableswhere table_schema="库名称";

-- 查询指定表的容量

select data_length, concat(round(sum(data_length/1024/1024),2),"MB") as DATAfrom information_schema.tableswhere table_schema="库名称"and table_name="表名称";
•••展开全文