84人参与 • 2026-05-10 • Mysql
select
date_format(create_time, '%y-%m') as 月份,
round(sum(data_length + index_length) / 1024 / 1024, 2) as 新增总空间_mb,
round(sum(data_length + index_length) / 1024 / 1024 / 1024, 2) as 新增总空间_gb
from
information_schema.tables
where
table_schema not in ('information_schema', 'mysql', 'performance_schema', 'sys') -- 排除系统库
and create_time is not null -- 只统计有创建时间的表
group by
date_format(create_time, '%y-%m')
order by
月份 desc;把 your_database 换成你的数据库名即可:
select
date_format(create_time, '%y-%m') as 月份,
round(sum(data_length + index_length) / 1024 / 1024, 2) as 新增空间_mb,
round(sum(data_length + index_length) / 1024 / 1024 / 1024, 2) as 新增空间_gb
from
information_schema.tables
where
table_schema = 'your_database' -- 替换成你的库名
and create_time is not null
group by
date_format(create_time, '%y-%m')
order by
月份 desc;create_time 是表创建时间,实际业务中更应该用 update_time(表最后修改时间) 代表每月数据增长:
select
date_format(update_time, '%y-%m') as 月份,
round(sum(data_length + index_length) / 1024 / 1024, 2) as 当月总占用_mb,
round(sum(data_length + index_length) / 1024 / 1024 / 1024, 2) as 当月总占用_gb
from
information_schema.tables
where
table_schema not in ('information_schema', 'mysql', 'performance_schema', 'sys')
and update_time is not null
group by
date_format(update_time, '%y-%m')
order by
月份 desc;data_length:数据文件大小index_length:索引文件大小data_length + index_length = 表总空间create_time:表创建时间update_time:表最后数据更新时间以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论