一 查看空间碎片-库维度
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
标签:语句,1024,系列,truncate,GB,mysql,table,data,schema From: https://www.cnblogs.com/danhuangpai/p/16809873.html