使用information.shema.tables查询数据库表大小

简介:

information_schema数据库中的表都是只读的,不能进行更新、删除和插入等操作,也不能加触发器,因为它们实际只是一个视图,不是基本表,没有关联的文件。
元数据描述数据的数据,用于描述数据属性信息。

常用字段:

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

查询test数据库中所有表格的大小:

select  table_name as 'tables',round(((data_length + index_length) / 1024 / 1024), 2) as MB from information_schema.tables where table_schema='test';

查询所有数据库的的大小:

>select table_schema as 'db',count(round(((data_length + index_length) / 1024 / 1024), 2)) as MB from  information_schema.tables group by table_schema;

猜你喜欢

转载自www.cnblogs.com/ww11/p/9056310.html