查询库中碎片大于1G的所有表
数据总大小:DATA_LENGTH+INDEX_LENGTH
实际表空间大小: TABLE_ROWS*AVG_ROW_LENGTH
碎片大小:(DATA_LENGTH+INDEX_LENGTH-TABLE_ROWS*AVG_ROW_LENGTH)/1024/1024/1024 碎片,单位G
整理的SQL:
select TABLE_SCHEMA,TABLE_NAME,ENGINE,concat(splinter,'G') '碎片(G)' from (
SELECT TABLE_SCHEMA,TABLE_NAME,ENGINE,ROUND((DATA_LENGTH+INDEX_LENGTH-TABLE_ROWS*AVG_ROW_LENGTH)/1024/1024/1024) splinter from information_schema.`TABLES` where TABLE_TYPE='BASE TABLE'
)a WHERE splinter >1 ORDER BY splinter DESC