您好,登錄后才能下訂單哦!
查看數(shù)據(jù)庫(kù)中表、索引和碎片大小的大?。?br/>select round(sum(data_length/1024/1024),2) as data_length_MB,
round(sum(index_length/1024/1024),2) as index_length_MB ,
round(sum(data_free/1024/1024),2) as data_free_MB ,table_name
from information_schema.tables where TABLE_SCHEMA= 'db_name' group by table_name order by 3 desc;更具查詢(xún)的結(jié)果進(jìn)行整理。
查看表的碎片情況:DATA_FREE
show TABLE status like 't_app_user';
或者查看:
select * from information_schema.tables where table_schema= 't_app_user';
生成批量腳本:
select CONCAT('alter table ',table_name , ' ENGINE=INNODB;') from information_schema.tables where TABLE_SCHEMA = 'db_chunqiu' and table_name like 't_app_user_head_%';
整理data_free大于100M的表:
select round(sum(data_length/1024/1024),2) as data_length_MB,
round(sum(index_length/1024/1024),2) as index_length_MB ,
round(sum(data_free/1024/1024),2) as data_free_MB ,CONCAT('alter table ',table_name , ' ENGINE=INNODB;') dd
from information_schema.tables where TABLE_SCHEMA= 'db_chunqiu' group by dd having data_free_MB >100 order by 3 desc;
進(jìn)行碎片整理:
alter table t_app_user ENGINE=INNODB;
整理前:
mysql> show TABLE status like 't_app_user'\G;
*************************** 1. row ***************************
Name: st_order_cal_record
Engine: InnoDB
Version: 10
Row_format: Dynamic
Rows: 3033960
Avg_row_length: 7117
Data_length: 21594390528
Max_data_length: 0
Index_length: 0
Data_free: 201046622208 --200G碎片左右
Auto_increment: 241541550
Create_time: 2018-05-04 16:17:26
Update_time: 2018-10-12 15:11:18
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
ERROR:
No query specified
整理后:
mysql> show TABLE status like 't_app_user'\G;
*************************** 1. row ***************************
Name: st_order_cal_record
Engine: InnoDB
Version: 10
Row_format: Dynamic
Rows: 3292968
Avg_row_length: 2038
Data_length: 6711918592
Max_data_length: 0
Index_length: 0
Data_free: 4194304 --4M整理后
Auto_increment: 241583900
Create_time: 2018-10-12 15:14:30
Update_time: 2018-10-12 15:57:51
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
ERROR:
No query specified
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。