it编程 > 数据库 > Mysql

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

80人参与 2026-05-10 Mysql

统计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)

您想发表意见!!点此发布评论

推荐阅读

MySQL事务&用户与权限管理方式

05-10

Mysql统计空间增量实现方式

05-10

MySQL之JDBC编程用法及说明

05-10

MYSQL的慢SQL优化的实现

05-10

MySQL GPG密钥过期问题及解决方案

05-10

服务从mysql迁移达梦数据库的实现方案

05-09

猜你喜欢

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

发表评论