mysql数据库容量查询

时间:2023-03-10 06:40:21
mysql数据库容量查询

1、统计每张表的数据量
SELECT
*
FROM
(
select
TABLE_NAME,
concat(
round(
sum(DATA_LENGTH / 1024 / 1024 ),
7
)

) as size
from
information_schema. tables
where
table_schema = 'platform_all_edu'
GROUP BY
table_name
) t;

2、统计每张表的数据容量(数据量+索引)
select
table_name,
(
sum(DATA_LENGTH) + sum(INDEX_LENGTH)
) / 1024 / 1024 as size
from
information_schema. tables
where
table_schema = 'platform_all_edu'
GROUP BY
table_name;

3、查看数据库数据量

SELECT concat(round(sum(DATA_LENGTH / 1024 / 1024 / 1024), 2), 'G')
FROM information_schema. tables
WHERE table_schema= 'platform_all_edu' ;