- 查看字符集
show global variables like 'innodb_file_format%';
如果不是Barracuda 则先设置innodb字符集 set global innodb_file_format=Barracuda
并修改mysql配置文件vi /etc/my.cnf 添加:
innodb_file_format=Barracuda
innodb_file_format_max=Barracuda
2. 修改表压缩:
alter table table_name ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;
表里已经有10个G的数据了,执行表压缩语句 大概执行了50分钟,最后数据压缩到1.48G
查看show table status like 'table_name'\G
建表时指定压缩:
CREATE TABLE table_name(id int NOT NULL,name varchar(32))ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8; --不设置KEY_BLOCK_SIZE,默认是16
注:顺序不能改变, 先设置字符集给事为 innodb_file_format=barracuda,然后再建表或者修改表的compaesed 。