查询表和 schema 的大小
MySQL存储命令
SELECT table_schema AS schema_name, table_name AS table_name, ROUND((data_length + index_length) / 1024 / 1024, 1) AS size_mb FROM information_schema.tables WHERE table_schema NOT IN ('mysql','information_schema','performance_schema','sys') ORDER BY (data_length + index_length) DESC LIMIT 20;作用
按数据和索引总大小(MB)列出最大的 20 个表。
适用场景
用于分析磁盘使用情况并找出哪些表占用空间。
注意
对于 InnoDB,information_schema 中的大小是近似值。如需按 schema 汇总,请只 GROUP BY table_schema,而不是 table_name。