1. 查询碎片超过10M的表
(1)整个数据库
SELECT
table_name,
round(data_length / 1024 / 1024) AS data_length_mb,
round(data_free / 1024 / 1024) AS data_free_mb
FROM
information_schema. TABLES
WHERE
TABLE_SCHEMA = 'xxx'
AND round(data_free / 1024 / 1024) > 10
ORDER BY
data_free_mb DESC
LIMIT 10;
(2) 单表查询
show table status from table_schema like '%[table_name]%';
2. MyISam 引擎
optimize table [table_name]
3. Innodb 引擎
alter table [table_name] engine= innodb
alter table [table_name] force;