数据容量查询
# 查看指定数据库容量大小
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)'
from information_schema.tables
order by data_length desc, index_length desc;
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 查询单个库中所有表磁盘占用大小
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)'
from information_schema.tables
where table_schema='mysql'
order by data_length desc, index_length desc;
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 查询单个数据库的总存储大小
SELECT
table_schema AS 'Database',
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'Total Size (MB)'
FROM
information_schema.tables
WHERE
table_schema = 'your_database_name'
GROUP BY
table_schema;
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
在线编辑 (opens new window)
上次更新: 2025/02/25, 18:30:54