当前位置: 代码网 > it编程>数据库>Mysql > 统计mysql数据库占用磁盘空间大小和行数实例

统计mysql数据库占用磁盘空间大小和行数实例

2026年05月10日 Mysql 我要评论
统计mysql数据库占用磁盘空间大小和行数1、查看占用磁盘空间大小select sum(t1.data_size ) as data_sum_size, sum(t1.index_size) as

统计mysql数据库占用磁盘空间大小和行数

1、查看占用磁盘空间大小

select sum(t1.data_size ) as data_sum_size,  
sum(t1.index_size) as index_sum_size
from(
select
table_name,
table_schema,
truncate(data_length/1024/1024,2) as data_size, -- 查看数据占用大小单位为mb
truncate(index_length/1024/1024,2) as index_size -- 查看索引占用大小 单位为mb
from information_schema.tables
where table_schema = '数据库名'
order by data_length desc) t1;

如果想查看该数据库中每个表占用大小的话

select
table_name,
table_schema,
truncate(data_length/1024/1024,2) as data_size, -- 查看数据占用大小单位为mb
truncate(index_length/1024/1024,2) as index_size -- 查看索引占用大小 单位为mb
from information_schema.tables
where table_schema = '数据库名'
order by data_length desc

2、查看数据库行数统计

select sum(t1.table_rows) as table_sum from (
select table_name,table_rows from information_schema.tables
where table_schema = '数据库名'
order by table_rows desc) t1;

如果要查看数据库中每个表的行数的话

select table_name,table_rows from information_schema.tables
where table_schema = '数据库名'
order by table_rows des

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2026  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com