溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

mysql 表碎片整理

發布時間:2020-05-26 08:40:27 來源:網絡 閱讀:799 作者:春秋小記 欄目:MySQL數據庫

查看數據庫中表、索引和碎片大小的大?。?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;更具查詢的結果進行整理。

查看表的碎片情況: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;

進行碎片整理:
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

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女