mysql 表碎片整理
admin
2023-04-21 13:43:12
0

查看数据库中表、索引和碎片大小的大小:
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

相关内容

热门资讯

燃气发电与电池储能相结合,成为... 来源:市场资讯 (来源:i商周) 孟菲斯一座xAI数据中心的燃气轮机 人工智能的用电飙升,让数据中心...
景嘉微:JM11性能大幅提升,... 有投资者在互动平台向景嘉微提问:“董秘您好!关注到近期有用户反馈公司JM11显卡推出了适配windo...
原创 v... 影像的发展进一步推动,不少品牌推出了专业影像手机,拥有2亿像素摄像头、色彩还原摄像头、影像芯片、影像...
荣耀首款自研耳夹式耳机官宣即将... 快科技5月13日消息,日前,荣耀首席营销官关海涛宣布,荣耀全场景团队自研首款耳夹式耳机马上上市,并称...
谷歌推出Googlebooks... IT之家 5 月 13 日消息,2026 年 I/O 开发者大会下周(5 月 19~20 日)召开之...
自控所推动GNC专业智能化升级 来源:滚动播报 (来源:中国航空报) 本报讯 5月6日,航空工业自控所召开 GNC+AI关键技术研发...
华电电力申请数据库访问方法专利... 国家知识产权局信息显示,华电电力科学研究院有限公司申请一项名为“数据库访问方法、装置、设备及介质”的...
苏州率先打造数据流通利用新范式 数据,作为第五大生产要素 具有流动性强、非消耗性、非均质性等特点 苏州率先打造数据流通利用新范式 夯...
伊媒披露伊美新一轮谈判5个先决... 当地时间5月12日,据伊朗法尔斯通讯社援引知情人士消息报道,伊朗对与美国新一轮谈判提出的5个先决条件...
英国将向霍尔木兹海峡多国护航行... 当地时间12日,总台记者从英国国防部获悉,英国将向在霍尔木兹海峡执行任务的多国护航行动提供无人机、战...