数据库表数据空洞处理

发布时间 2023-03-26 23:20:14作者: zhengbiyu

查看数据库表使用情况

//show table status是有缓存的,执行前最好先执行以下语句
ANALYZE TABLE 表名;
//update_time列表示表数据最后修改时间
show table status;

查看数据库表数据空洞大小

SELECT table_schema AS '数据库',
    TABLE_NAME AS '表名',
    table_rows AS '记录数',
    truncate(data_length/1024/1024, 2) AS '数据容量(MB)',
    truncate(data_free/1024/1024, 2) AS '数据空洞(MB)',
    truncate(index_length/1024/1024, 2) AS '索引容量(MB)'
FROM information_schema.tables ORDER BY data_length DESC,index_length DESC;

回收空洞

alter table 表名 engine ='innodb';