在 MySQL 中查看数据表大小
查看当前数据库所有表大小
SELECT
table_name AS `Table`,
ROUND(data_length / 1024 / 1024, 2) AS `Data Size (MB)`,
ROUND(index_length / 1024 / 1024, 2) AS `Index Size (MB)`,
ROUND((data_length + index_length) / 1024 / 1024, 2) AS `Total Size (MB)`
FROM information_schema.tables
WHERE table_schema = DATABASE()
ORDER BY (data_length + index_length) DESC;
说明:
data_length:数据大小index_length:索引大小table_schema = DATABASE():当前数据库
查看指定数据库的表大小
SELECT
table_name AS `Table`,
ROUND((data_length + index_length) / 1024 / 1024, 2) AS `Total Size (MB)`
FROM information_schema.tables
WHERE table_schema = 'your_database_name'
ORDER BY (data_length + index_length) DESC;
查看单个表大小
SELECT
table_name AS `Table`,
ROUND((data_length + index_length) / 1024 / 1024, 2) AS `Total Size (MB)`
FROM information_schema.tables
WHERE table_schema = 'your_database_name'
AND table_name = 'your_table_name';
查看所有数据库大小
SELECT
table_schema AS `Database`,
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS `Total Size (MB)`
FROM information_schema.tables
GROUP BY table_schema;
补充
也可以直接用:
SHOW TABLE STATUS;
会显示:
Data_lengthIndex_lengthRows等信息