在開發中,創建了需要備份60天數據的表‘machine_n01_history_archive’,爲了提高備份效率,對該表進行特殊設計:
設計該表爲壓縮表
Mysql開發手冊中指出,“In particular, compressed tables use less disk space and so require less disk I/O to read and write the data. Compression is available for all kinds of workloads with InnoDB
tables, and for read-only MyISAM
tables.”
並且指出壓縮表不能用於系統表空間,如
Compressed tables can be created in file-per-table tablespaces or in general tablespaces. Table compression is not available for the InnoDB system tablespace.
如何設置mysql innodb 表的壓縮(Creating a Compressed Table in File-Per-Table Tablespace):
第一,mysql的版本需要大於5.5;
第二,查看當前InnoDB的表空間;可以使用SHOW VARIABLES; 命令,查看innodb_file_per_table選項是否開啓?如果沒有開啓,表示innodb將被創建於系統表空間中。可以在my.cnf
or my.ini中修改該選項,也可以使用命令
SET GLOBAL innodb_file_per_table=1;進行修改。
第三,create table或者alter talble 增加 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8; 根據經驗,一般壓縮比例可以達到30%-40%。
如果指定ROW_FORMAT = COMPRESSED,則可以省略KEY_BLOCK_SIZE; KEY_BLOCK_SIZE設置默認爲innodb_page_size值的一半。
如果指定有效的KEY_BLOCK_SIZE值,則可以省略ROW_FORMAT = COMPRESSED; 壓縮會自動啓用。
(innodb_file_format=Barracuda)
CREATE TABLE t1 (c1 INT PRIMARY KEY) ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;