Mysql表的碎片整理和空间回收

OPTIMIZE TABLE TableName; -- 优化表碎片(会锁表,数据量大的表执行时间相对较长)

show table status from database_test like ‘TableName‘; -- 查询表状态

SELECT table_schema,TABLE_NAME , concat(data_free/1024/1024,"M") FROM `information_schema`.tables WHERE data_free >8*1024*1024 AND ENGINE =‘innodb‘ ORDER BY data_free DESC; -- 查询表碎片空间占用较大的表

相关文章