MySQL数据和索引占用空间查询

来源:互联网 发布:平刷王重庆时时彩软件 编辑:程序博客网 时间:2024/05/18 14:25

链接地址
对原文代码进行了修改,如下:

关于查数据库和表中的数据和索引所占空间的大小的SQL方法:
查询information_schema架构中的tables表。
代码:
查询所有数据库占用磁盘空间大小的SQL语句:

select table_schema,concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_sizefrom information_schema.tablesgroup by table_schemaorder by sum(data_length) desc;

这里写图片描述

查询单个库中所有表磁盘占用大小的SQL语句:

select table_name,concat(truncate(data_length/1024/1024,2),'MB') as data_size,concat(truncate(index_length/1024/1024,2),'MB') as index_sizefrom information_schema.tables where table_schema='employees'order by data_length desc;

这里写图片描述

0 0