Mysql

Mysql 8 表大小

  • May 26, 2021

我們遇到了伺服器上表大小不合理的問題,例如:

昨天創建了一個帶分區的表,開始將數據寫入特定分區。

mysql> show table status like 'in_followers_bots_p'\G
*************************** 1. row ***************************
          Name: in_followers_bots_p
        Engine: InnoDB
       Version: 10
    Row_format: Dynamic
          Rows: 38517
Avg_row_length: 73
   Data_length: 2818048
Max_data_length: 0
  Index_length: 1589248
     Data_free: 4194304
Auto_increment: NULL
   Create_time: 2021-05-04 14:58:32
   Update_time: 2021-05-04 14:59:45
    Check_time: NULL
     Collation: utf8mb4_unicode_ci
      Checksum: NULL
Create_options: partitioned
       Comment: 

但同時,這個表(分區)在磁碟上的大小為 3.7G

-rw-r----- 1 mysql mysql 3.7G May 5 12:29 in_followers_bots_p#p#p05.ibd

mysql Ver 8.0.20

Centos 8

許多表都觀察到此問題,請告訴我此問題的原因以及是否有解決方案。我很樂意提供所有必要的資訊。

UPD

mysql> SHOW CREATE TABLE in_followers_bots_p\G
*************************** 1. row ***************************
      Table: in_followers_bots_p
Create Table: CREATE TABLE `in_followers_bots_p` (
 `owner_id` bigint unsigned NOT NULL DEFAULT '0',
 `bot_id` bigint unsigned NOT NULL DEFAULT '0',
 `month_id` tinyint NOT NULL,
 PRIMARY KEY (`bot_id`,`owner_id`,`month_id`),
 KEY `in_followers_bots_owner_id_index` (`owner_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
/*!50100 PARTITION BY RANGE (`month_id`)
(PARTITION p01 VALUES LESS THAN (2) ENGINE = InnoDB,
PARTITION p02 VALUES LESS THAN (3) ENGINE = InnoDB,
PARTITION p03 VALUES LESS THAN (4) ENGINE = InnoDB,
PARTITION p04 VALUES LESS THAN (5) ENGINE = InnoDB,
PARTITION p05 VALUES LESS THAN (6) ENGINE = InnoDB,
PARTITION p06 VALUES LESS THAN (7) ENGINE = InnoDB,
PARTITION p07 VALUES LESS THAN (8) ENGINE = InnoDB,
PARTITION p08 VALUES LESS THAN (9) ENGINE = InnoDB,
PARTITION p09 VALUES LESS THAN (10) ENGINE = InnoDB,
PARTITION p10 VALUES LESS THAN (11) ENGINE = InnoDB,
PARTITION p11 VALUES LESS THAN (12) ENGINE = InnoDB,
PARTITION p12 VALUES LESS THAN (13) ENGINE = InnoDB) */```

通過使用參數將數據傳輸到分區表來解決問題ROW_FORMAT=COMPRESSED

引用自:https://dba.stackexchange.com/questions/291029