一、compact和redundant行记录模式
MySQL 5.1中Innodb存储引擎(Built-in-InnoDB)提供了compact和redundant两种格式来记录行数据,redundant是为了兼容之前版本保留的。默认情况下保存的格式为compact格式。可以通过命令show table staus like 'table_name'查看当前表使用的行格式(对应查询结果中的Row_format值)。
对于compact行记录模式:不管char还是varchar类型,NULL值都不占用存储空间。
对于redundant行记录模式:varchar类型的NUL值不占用存储空间,而char类型需要占用存储空间。
二、dynamic和compressed行记录模式
Innodb plugin引入新的文件格式Barracuda,并将以前支持的compact和redundant行记录模式称为Antelope文件格式。
Barracuda文件格式包含两种新的行记录格式:Dynamic和Compressed。
这两种文件格式在处理行溢出时候,Antelope会存放768个前缀字节,Barracuda只会存放20个字节的指针,见下图。

同时,选择文件格式对应的参数innodb_file_format,默认为Antelope。
其他详细的可以参考:http://dev.mysql.com/doc/innodb/1.1/en/innodb-row-format-dynamic.html
再来一张图:

上面的笔记来自:
1、《MySQL技术内幕InnoDB存储引擎》
2、《InnoDB Internals: InnoDB File Formats and Source Code Structure》
三、问题解决
在一次机器升级中涉及到数据库迁移,MYSQL版本都是5.1.x,从一个没有装innodb plugin的版本的数据库A通过mysqldump出来,恢复到装有innodb plugin版本的数据库B中其中一张表报错,B中报错类似如下:
root@test 04:10:58>create table tmp_zx ( a int) engine = innodb row_format = dynamic;
ERROR 1005 (HY000): Can't create table 'test.tmp_zx' (errno: 1478 )
原因是B中innodb_file_format中默认值为默认的Antelope:
root@test 04:17:58>show variables where variable_name in ('innodb_file_per_table','innodb_file_format','innodb_version');
+-----------------------+----------+
| Variable_name | Value |
+-----------------------+----------+
| innodb_file_format | Antelope |
| innodb_file_per_table | ON |
| innodb_version | 1.0.9 |
+-----------------------+----------+
3 rows in set (0.00 sec)
动态修改为innodb_file_format 为 Barracuda 就可以。
但是原来A中没有装plugin怎么能有row_format = dynamic的表?
其实原因在于开发创建时候,虽然选择row_format = dynamic但是实际上转换为Compact(可以参考说明:http://dev.mysql.com/doc/innodb-plugin/1.0/en/innodb-compression-syntax-warnings.html),但是在Create_options: row_format=DYNAMIC中保留这个选项,mysqldump导出表结构时候就保留原来创建时候的选项。在A中情况如下:
root@localhost 16:25:40>show variables where variable_name in ('innodb_file_format','innodb_version');
Empty set (0.00 sec)root@localhost 16:25:42>create table tmp_zx ( a int) engine = innodb row_format = dynamic;
Query OK, 0 rows affected (0.20 sec)root@localhost 16:25:50>show table status like 'tmp_zx'\G
*************************** 1. row ***************************
Name: tmp_zx
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: 2011-07-24 16:25:50
Update_time: NULL
Check_time: NULL
Collation: gbk_chinese_ci
Checksum: NULL
Create_options: row_format=DYNAMIC
Comment:
1 row in set (0.00 sec)root@localhost 16:25:56>show create table tmp_zx\G
*************************** 1. row ***************************
Table: tmp_zx
Create Table: CREATE TABLE `tmp_zx` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=gbk ROW_FORMAT=DYNAMIC
1 row in set (0.00 sec)
--EOF--
http://www.chenyajun.com/2009/02/13/2133
Link | 08月 11th, 2011 at 12:41
貌似也是挺久没跟新了啊!
Link | 10月 10th, 2011 at 13:52