对于越来越多的数据,数据库的容量越来越大,压缩也就越来越常见了。在我的实际工作中进行过多次压缩工作,也遇到多次问题,在此和大家分享一下。

首先,我们先说说怎么使用innodb的压缩.

第一,mysql的版本需要大于5.5
第二,设置innodb_file_format=barracuda
第三,create table或者alter talble 增加 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;(默认的key_block_size=16)

其实很简单,根据经验,一般压缩比例可以达到30%-40%

然后,我们说说我在压缩过程中遇到的坑和发现的关联,当然有些比较二。

No1:


问题:使用脚本批量alter操作,只动态修改了实例的innodb_file_format=barracuda,然后alter所有数据库中的表。并没有修改配置文件中的设置。

结果:表中已有数据被压缩,但是在重启之后,由于innodb_file_format参数被重新修改成antelope,导致后续写入的数据没有被压缩(虽然表结构中有row_format=compressed,但是不会起作用),最终表体积仍然很大。

教训:实例和配置文件要同步修改。(这个错误最二,太低级 T_T,不解释了。)

No2:


问题:在innodb_file_format=antelope的情况下,建立压缩表(表结构中带有row_format=compressed),然后在设置innodb_file_format=barracuda。

结果:表结构中的row_format=compressed被忽略,后续写入表的数据并没有被压缩,最终导致表体积大。

教训:先修改innodb_file_format(session和global都需要修改),在create table或者alter table。

但是以上这点有个坑人的地方,在错误的顺序下,表是可以被成功建立了,只是会有warning,但是表结构中会有row_format=compressed,在后期排查的时候非常误导人!

+--------------------------+----------+
| 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_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;
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_SIZE=8. |
| Warning | 1478 | InnoDB: ROW_FORMAT=COMPRESSED requires innodb_file_format > Antelope. |
| Warning | 1478 | InnoDB: assuming ROW_FORMAT=COMPACT. |
+---------+------+-----------------------------------------------------------------------+
4 rows in set (0.00 sec)

我们可以从warnings中看见,压缩设置被忽略了。但是最坑爹的一点是,如果我们show create table会有如下结果:

test_1 | CREATE TABLE `test_1` (
`x` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8

在这种情况下,我们吸取教训,不能使用show create table看压缩状态,而是应该用show table status;

show table status like 'test_1'\G;
*************************** 1. row ***************************
Name: test_1
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 0
Avg_row_length: 0
Data_length: 16384
Max_data_length: 0
Index_length: 0
Data_free: 0
Auto_increment: NULL
Create_time: 2013-09-27 15:59:13
Update_time: NULL
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options: row_format=COMPRESSED KEY_BLOCK_SIZE=8
Comment:
1 row in set (0.00 sec)

坑爹啊,不说了。正常应该这个样子

show table status like 'test_2'\G;
*************************** 1. row ***************************
Name: test_2
Engine: InnoDB
Version: 10
Row_format: Compressed
Rows: 0
Avg_row_length: 0
Data_length: 8192
Max_data_length: 0
Index_length: 0
Data_free: 0
Auto_increment: NULL
Create_time: 2013-09-27 16:09:51
Update_time: NULL
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options: row_format=COMPRESSED KEY_BLOCK_SIZE=8
Comment:
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_format=barracuda而innodb_file_format_max=antelop,那么在建立压缩表的时候,max会自动变成barracuda。

localhost.test>show 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.00 sec) localhost.test>create table test_4(x int) ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;
Query OK, 0 rows affected (0.01 sec) localhost.test>show 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的值。

Mysql [Err] 1118 - Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535.的更多相关文章

  1. mysql 1709: Index column size too large. The maximum column size is 767 bytes.

    1709: Index column size too large. The maximum column size is 767 bytes. 修改排序规则解决 utf8_general_ci

  2. Index column size too large. The maximum column size is 767 bytes.

    mysql建表时报Index column size too large. The maximum column size is 767 bytes.解决办法:在建表语句的后面加入:ENGINE=In ...

  3. ERROR 1709 (HY000): Index column size too large. The maximum column size is 767 bytes.

    MySQL版本5.6.35 在一个长度为512字符的字段上创建unique key报错 CREATE DATABASE dpcs_metadata DEFAULT CHARACTER SET utf8 ...

  4. Mysql [Err] 1118 - Row size too large

    首先声明,对MySQL不懂,很多都不知道原因 设计了一个表,里面很多text字段,然后填进去的东西太多(用的是Python的MySQLdb),报错: _mysql_exceptions.Operati ...

  5. mysql触发器应用和创建表错误代码: 1118 Row size too large. 解决

    1.针对数据库查询问题的方便,可以建立重要表的log备份记录表,在主表的添加,修改,删除添加触发器,修改触发器增加触发字段的点,限制条件. 数据库log表查问题比从线上多台服务器上下载日志文件相对方便 ...

  6. mysql 报Row size too large 65535 原因与解决方法

    报错信息:Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535 ...

  7. Mysql_大字段问题Row size too large.....not counting BLOBs, is 8126.

    [问题描述] 1.从myslq(5.7.19-0ubuntu0.16.04.1)中导出sql脚本,导入到mysql(5.5.27)中,报如下错误:Row size too large. The max ...

  8. The maximum column size is 767 bytes (Mysql)

     ERROR app.wsutils 419 INCRON: Error: ('HY000', '[HY000] [MySQL][ODBC 5.2(w) Driver][mysqld-5.7.7-rc ...

  9. 【bug】 1118 Row size too large

    1118 Row size too large Every table (regardless of storage engine) has a maximum row size of 65,535 ...

随机推荐

  1. .NET Web API - 去掉讨厌的$id并且强制返回json格式

    // 只返回json字符串,屏蔽自动选择xml格式的可能性,同时去掉讨厌的$id var json = config.Formatters.JsonFormatter; json.Serializer ...

  2. Bootstrap:解决Bootstrap下拉框需要双击才能打开的问题

    当使用AngularJS和Bootstrap时,会发生菜单栏navbar控件 需要点击两下才能打开的问题.解决的方法就是在页面加载后,执行如下语句: // 防止下拉菜单需要双击的bug $('.dro ...

  3. jQuery EasyUI 1.4更新记录

    问题: menu:修复当删除一个menu项时.menu高度不准确. datagrid:修复当datagrid宽度太小时,fitColumns方法不能使用. 改进: 1.为easyui全部组件新增了自适 ...

  4. 使用Win32 API实现生产者消费者线程同步

    使用win32 API创建线程,创建信号量用于线程的同步 创建信号量 语法例如以下 HANDLE semophore; semophore = CreateSemaphore(lpSemaphoreA ...

  5. UpMarqueeTextView-模仿淘宝client向上滚动的广告条

    UpMarqueeTextView一个简单的向上滚动的相似跑马灯效果,项目中用到的时候是接受到推送过来的消息向上滚动一次.没有做动态的gif效果,所以都是一些纯文字的简单记录. UpMarqueeTe ...

  6. 保护眼睛-eclipse黑色背景设置

    eclipse中java编辑器颜色改动,适合程序员人群: 长时间编码,眼睛是有非常大负担的,特别是使用eclipse,它自带的java编辑器背景色是刺眼的白色.代码颜色基本是黑色,这样一个编辑器里白色 ...

  7. B1230 [Usaco2008 Nov]lites 开关灯 线段树

    就是线段树维护异或和.之前我线段树区间修改down都是修改当前区间,结果debug出不来,改成每次向下了. 题干: Description Farmer John尝试通过和奶牛们玩益智玩具来保持他的奶 ...

  8. django自带权限控制系统的使用和分析

    1.django的权限控制相关表及其相互间的关系: django的所有权限信息存放在auth_permission表中,用户user和用户组group都可以有对应的权限permission.分别存放在 ...

  9. (Go)08.time示例

    package main import ( "fmt" "time" ) func test() { ) } func main() { now := time ...

  10. php循环跳出

    PHP中的循环结构大致有for循环,while循环,do{} while 循环以及foreach循环几种,不管哪种循环中,在PHP中跳出循环大致有这么几种方式: 代码: <?php $i = 1 ...