1、查詢所有數(shù)據(jù)庫(kù)占用磁盤空間大小
select
TABLE_SCHEMA,
concat(truncate(sum(data_length)/1024/1024,2),' MB') as data_size,
concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
from information_schema.tables
group by TABLE_SCHEMA
ORDER BY data_size desc;
2、查詢單個(gè)庫(kù)中所有表磁盤占用大小
select
TABLE_NAME,
concat(truncate(data_length/1024/1024,2),' MB') as data_size,
concat(truncate(index_length/1024/1024,2),' MB') as index_size
from information_schema.tables
where TABLE_SCHEMA = 'xinyar_erp'
group by TABLE_NAME
order by data_length desc;
3、使用optimize命令
optimize table tb_report_inventory;
使用的時(shí)間比較長(zhǎng),需要耐心等待。
注意:optimize執(zhí)行時(shí)會(huì)將表鎖住,所以不要在高峰期使用。也不要經(jīng)常使用,每月一次就足夠了