做网站需要搭建服务器么,ui设计学校,网站备案密码忘,南京在线网站制作对于越来越多的数据#xff0c;数据库的容量越来越大#xff0c;压缩也就越来越常见了。在我的实际工作中进行过多次压缩工作#xff0c;也遇到多次问题#xff0c;在此和大家分享一下。首先#xff0c;我们先说说怎么使用innodb的压缩.第一#xff0c;mysql的版本需要大…对于越来越多的数据数据库的容量越来越大压缩也就越来越常见了。在我的实际工作中进行过多次压缩工作也遇到多次问题在此和大家分享一下。首先我们先说说怎么使用innodb的压缩.第一mysql的版本需要大于5.5第二设置innodb_file_formatbarracuda第三create table或者alter talble 增加 ROW_FORMATCOMPRESSED KEY_BLOCK_SIZE8;(默认的key_block_size16)其实很简单根据经验一般压缩比例可以达到30%-40%然后我们说说我在压缩过程中遇到的坑和发现的关联当然有些比较二。No1问题使用脚本批量alter操作只动态修改了实例的innodb_file_formatbarracuda然后alter所有数据库中的表。并没有修改配置文件中的设置。结果表中已有数据被压缩但是在重启之后由于innodb_file_format参数被重新修改成antelope导致后续写入的数据没有被压缩(虽然表结构中有row_formatcompressed但是不会起作用)最终表体积仍然很大。教训实例和配置文件要同步修改。(这个错误最二太低级 T_T不解释了。)No2:问题在innodb_file_formatantelope的情况下建立压缩表(表结构中带有row_formatcompressed)然后在设置innodb_file_formatbarracuda。结果表结构中的row_formatcompressed被忽略后续写入表的数据并没有被压缩最终导致表体积大。教训先修改innodb_file_format(session和global都需要修改)在create table或者alter table。但是以上这点有个坑人的地方在错误的顺序下表是可以被成功建立了只是会有warning但是表结构中会有row_formatcompressed在后期排查的时候非常误导人------------------------------------| Variable_name | Value |------------------------------------| innodb_file_format | Antelope || innodb_file_format_check | ON || innodb_file_format_max | Antelope |------------------------------------3 rows in set (0.00 sec)test create table test_1 (x int) ROW_FORMATCOMPRESSED KEY_BLOCK_SIZE8;Query OK, 0 rows affected, 4 warnings (0.07 sec)test show warnings;--------------------------------------------------------------------------------------| Level | Code | Message |--------------------------------------------------------------------------------------| Warning | 1478 | InnoDB: KEY_BLOCK_SIZE requires innodb_file_format Antelope. || Warning | 1478 | InnoDB: ignoring KEY_BLOCK_SIZE8. || Warning | 1478 | InnoDB: ROW_FORMATCOMPRESSED requires innodb_file_format Antelope. || Warning | 1478 | InnoDB: assuming ROW_FORMATCOMPACT. |--------------------------------------------------------------------------------------4 rows in set (0.00 sec)我们可以从warnings中看见压缩设置被忽略了。但是最坑爹的一点是如果我们show create table会有如下结果test_1 | CREATE TABLEtest_1 (xint(11) DEFAULT NULL) ENGINEInnoDB DEFAULT CHARSETutf8 ROW_FORMATCOMPRESSED KEY_BLOCK_SIZE8在这种情况下我们吸取教训不能使用show create table看压缩状态而是应该用show table status;show table status like test_1\G;*************************** 1. row ***************************Name: test_1Engine: InnoDBVersion:10Row_format: CompactRows:0Avg_row_length:0Data_length:16384Max_data_length:0Index_length:0Data_free:0Auto_increment:NULLCreate_time:2013-09-27 15:59:13Update_time:NULLCheck_time:NULLCollation: utf8_general_ciChecksum:NULLCreate_options: row_formatCOMPRESSED KEY_BLOCK_SIZE8Comment:1 row in set (0.00 sec)坑爹啊不说了。正常应该这个样子show table status like test_2\G;*************************** 1. row ***************************Name: test_2Engine: InnoDBVersion:10Row_format: CompressedRows:0Avg_row_length:0Data_length:8192Max_data_length:0Index_length:0Data_free:0Auto_increment:NULLCreate_time:2013-09-27 16:09:51Update_time:NULLCheck_time:NULLCollation: utf8_general_ciChecksum:NULLCreate_options: row_formatCOMPRESSED KEY_BLOCK_SIZE8Comment:1 row in set (0.00 sec)No3:发现和innodb_file_format相关的2个参数:-------------------------------------| Variable_name | Value |-------------------------------------| innodb_file_format | Barracuda || innodb_file_format_check | ON || innodb_file_format_max | Barracuda |-------------------------------------3 rows in set (0.00 sec)官方的解释可以参考如下的链接http://dev.mysql.com/doc/refman/5.5/en/innodb-parameters.html#sysvar_innodb_file_format测试过程中发现如果是innodb_file_formatbarracuda而innodb_file_format_maxantelop那么在建立压缩表的时候max会自动变成barracuda。localhost.testshow global variables like innodb_file_format%;-------------------------------------| Variable_name | Value |-------------------------------------| innodb_file_format | Barracuda || innodb_file_format_check | ON || innodb_file_format_max | Antelope |-------------------------------------3 rows in set (0.00sec)localhost.testcreate table test_4(x int) ROW_FORMATCOMPRESSED KEY_BLOCK_SIZE8;Query OK,0 rows affected (0.01sec)localhost.testshow global variables like innodb_file_format%;-------------------------------------| Variable_name | Value |-------------------------------------| innodb_file_format | Barracuda || innodb_file_format_check | ON || innodb_file_format_max | Barracuda |-------------------------------------3 rows in set (0.00 sec)如果innodb_file_format_check这参数解释的决定innodb是否会检查共享表空间中的表格式的tag如果检查开启那么当标记的表格式的tag高于innodb可以支撑的表格式那么innodb会报错并停止启动。如果支持那么会将innodb_file_format_max的值改为这个tag的值。