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;
表占用分析
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 = 'adolphor'
order by data_length desc, index_length desc;
参考资料
文档信息
- 本文作者:Bob.Zhu
- 本文链接:https://adolphor.github.io/2022/04/25/01-mysql-storage-space-analysis/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)