数据库(表)查看表大小和索引所占内存空间

该博客提供了查询MySQL数据库中所有数据表大小、按大小排序、取前10及保留小数的方法,同时也展示了如何查询每个数据库的总容量和排名前10的数据库。此外,还给出了查看特定数据库中索引占用内存空间的查询语句。
摘要由CSDN通过智能技术生成

一. 表大小

1. 查询所有数据表的大小,并排序

use information_schema;
# 正序
select table_schema as '库名', table_name as '表名', round(data_length/1024/1024) as '表大小(M)' from tables order by 表大小(M);

# 逆序
select table_schema as '库名', table_name as '表名', round(data_length/1024/1024) as '表大小(M)' from tables order by 表大小(M) DESC;

# 取排名前10
select table_schema as '库名', table_name as '表名', round(data_length/1024/1024) as '表大小(M)' from tables order by 表大小(M) DESC limit 1,10;

# 取排名前10,保留两位小数(四舍五入)
select table_schema as '库名', table_name as '表名', round(data_length/1024/1024,2) as '表大小(M)' from tables order by 表大小(M) DESC limit 1,10;

2. 查询所有数据库的大小

use information_schema;

# 查询所有数据库的数据量大小 
select table_schema as '库名', table_name as '表名', round(sum(data_length/1024/1024)) as '表大小(M)' from tables group by table_schema;

# 查询所有数据库容量大小,并排序
select table_schema as '库名', round(sum(data_length/1024/1024)) as '库大小(M)' from tables group by table_schema;

# 查询所有数据库容量大小,显示数据量最多的前十个库
select table_schema as '库名', round(sum(data_length/1024/1024)) as '库大小(M)' from tables group by table_schema desc limit 10;

3. 查询数据库总容量

use information_schema;
select table_schema as '库名', round(sum(data_length/1024/1024)) as '库大小(M)' from tables;

二. 索引占用内存空间

select  table_name, round(index_length/1024/1024,2) as '索引内存(M)' from tables where table_schema = <库名>;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值