我的博客
欢迎来到我的博客
bunny.icu

MySQL查看数据库和表占用的空间大小

MySQL查看数据库和表占用的空间大小

MySQL查看数据库和表占用的空间大小

查看 MySQL「所有库」的容量大小

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)',
sum(truncate(DATA_FREE/1024/1024, 2)) as '碎片占用(MB)'
from information_schema.tables
group by table_schema
order by sum(data_length) desc, sum(index_length) desc;

查看 MySQL「指定库」的容量大小

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)',
sum(truncate(DATA_FREE/1024/1024, 2)) as '碎片占用(MB)'
from information_schema.tables
where table_schema='table_name'
order by data_length desc, index_length desc;

查看 MySQL「指定库」中「所有表」的容量大小

SELECT
  table_schema as '数据库',
  table_name as '表名',
  table_rows as '记录数',
  truncate(data_length/1024/1024, 2) as '数据容量(MB)',
  truncate(index_length/1024/1024, 2) as '索引容量(MB)',
  truncate(DATA_FREE/1024/1024, 2) as '碎片占用(MB)'
from 
  information_schema.tables
where 
  table_schema='table_name'
order by 
  data_length desc, index_length desc;

Reference

如何查看 MySQL 数据库容量大小,表容量大小,索引容量大小?找到占用空间最大的表

版权声明


本作品系原创, 转载须遵循 CC BY-NC-ND 4.0 许可协议
本文标题:MySQL查看数据库和表占用的空间大小
本文链接:https://www.bunny.icu/archives/1549

推荐文章

发表评论

textsms
account_circle
email

bunny.icu

MySQL查看数据库和表占用的空间大小
MySQL查看数据库和表占用的空间大小 查看 MySQL「所有库」的容量大小 SELECT table_schema as '数据库', sum(table_rows) as '记录数', sum(truncate(data_length/1024/1024, 2)) as '…
扫描二维码继续阅读
2022-10-01