一 查看空間碎片-庫維度
select table_schema as '數據庫', sum(table_rows) as '記錄數', sum(truncate(data_length/1024/1024/1024, 2)) as '數據容量(GB)', sum(truncate(index_length/1024/1024/1024, 2)) as '索引容量(GB)', sum(truncate(data_free/1024/1024/1024, 2)) as '空間碎片(GB)' from information_schema.tables group by table_schema
二 查看空間碎片-表維度
select table_name as '數據庫', table_rows as '記錄數', truncate(data_length/1024/1024/1024, 2) as '數據容量(GB)', truncate(index_length/1024/1024/1024, 2) as '索引容量(GB)', truncate(data_free/1024/1024/1024, 2) as '空間碎片(GB)' from information_schema.tables WHERE TABLE_SCHEMA='xxx' order by data_free desc limit 10