SHOW TABLE STATUS FROM database; -- 替换为你的数据库名称
注意:(DATA_LENGTH + INDEX_LENGTH)/1024/1024 得出的结果是大小单位是MB
SELECT
SUM(ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024, 2)) AS Size_MB
FROM
INFORMATION_SCHEMA.TABLES
WHERE
TABLE_SCHEMA = 'database'; -- 替换为你的数据库名称
SELECT
TABLE_NAME AS Name,
ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024, 2) AS Size_MB
FROM
INFORMATION_SCHEMA.TABLES
WHERE
TABLE_SCHEMA = 'database' -- 替换为你的数据库名称
AND TABLE_NAME IN ('table_name', 'table_name', 'table_name');
SELECT SUM(Size_MB) AS Total_Size_MB
FROM (
SELECT sum(ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024, 2)) AS Size_MB
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'database'
UNION ALL
SELECT sum(ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024, 2)) AS Size_MB
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'database'
UNION ALL
SELECT sum(ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024, 2)) AS Size_MB
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'database'
) AS total_sizes;