Source: kelvin19840813 's blog http://www.cnblogs.com/kelvin19840813/
Your support is the greatest encouragement to bloggers, thank you for your serious reading. The copyright of this article is owned by the author, welcome reprint, but please keep this statement.
Many people know that Mysqlbinlog explains the Binlog insert, update is in the opposite position, and the table field is @1 ... @ number, it's disgusting!!!
But did not see someone in the mysql8.0 function requirements when asked to come out, they did not propose
Only to explain the frm file, get the table field name, fields, and then corresponding to the sticker to translate the Binlog SQL statement is not a profound thing, only this diary record
0000 ~ 0001:fe 01 Identify if frm file, fixed
0002:0A is the frm_ver+3+ my_test (Create_info->varchar) of the MySQL version identification location table.cc; For 6 is the 5.0+ version of MySQL, 9 or 10 is the frm file with varchar
0003:0C innuendo enumeration values from the Handler.h file Legacy_db_type, 0 C is 12 just good is the InnoDB type, as follows:
Enum Legacy_db_type
{
Db_type_unknown=0,db_type_diab_isam=1,
..., Db_type_innodb,
......
};
0004 ~ 0005:03 00, the inverse view of the MySQL 5.0+ is always 3, if not 3, then even ...
0006 ~ 0007:00 10, looking back at the io_size:4096
0008 ~ 0009:01 00 I don't know what it is yet.
000a ~ 000d:00 40 00 00 I don't know what it is yet.
000e ~ 000f:f9 tmp_key_length; if equals 0xffff then the key length is 4 byte integer offset 0x002f
0010 ~ 0011:18 rec_length; This is a default value that stores the byte of a string
0012 ~ 0015:00 00 00 00 is the Max_Rows option for the CREATE TABLE statement
0016 ~ 0019:00 00 00 00 is the Min_rows option for the CREATE TABLE statement, in the Handler.h file
typedef struct ST_HA_CREATE_INFORMATION
{
.......
ULONGLONG Max_rows,min_rows;
...}
001a:00 no use.
001B:02 always 2, using long package fields
001c ~ 001d:a3 key_info_length- keyinfo partial byte size
001e ~ 001f:69 00 is a variable of the value of CREATE TABLE [table_option] my_base.h file ha_option_*
0020: Useless
0021:05 is the version number of the frm file
0022 ~ 0025:00 00 00 00 is the avg_row_length specified by the CREATE TABLE [Table_option]
0026:create table [Table_option] Specifies the character set encoding [DEFAULT] CHARACTER Set
0027:00 Don't know
0028:02 is the row_format of CREATE TABLE [Table_option]
Rem0types.h file
Enum Rec_format_enum {
rec_format_redundant= 0,/*!< Redundant row FORMAT */
rec_format_compact= 1,/*!< COMPACT Row FORMAT */
rec_format_compressed= 2,/*!< Compressed Row FORMAT */
rec_format_dynamic= 3/*!< DYNAMIC Row FORMAT */
};
0029:00 Raid_type MySQL 5 before the CREATE TABLE [table_option], no research on why
002a:00 raid_chunks MySQL 5 before the CREATE TABLE [table_option], no research on why
002b ~ 002e:00 xx raid_chunksize MySQL 5 before the CREATE TABLE [table_option], no research why
002f ~ 0032:f9 to index metadata KeyInfo partial byte size
0033 ~ 0036:BF C5 the MySQL version number, relates to a byte order problem, the machine is x86 so is Little-endian, the link is as follows:
Http://baike.baidu.com/link?url=Dd2Z3o5aNoUYQPG6xqIgNwr-jrNS8BTK72r42WVxr-SHhva4TnMsHrEXTcE_N4F6ZEhhe18Akg3hOBe2Eb-M9K
are unsigned int (4 bytes), Little-endian
Generate Mysql_version_major, Mysql_version_minor, Mysql_version_patch
0037 ~ 003a:33 (XX) CREATE TABLE [table_option] Extra_info information
- CONNECTION
- ENGINE
- PARTITION by
- With PARSER
- Table COMMENT
003b ~ 003c:00 xx extra_rec_buf_length
003d:00 if 0C, is the partition table, db_type_partition_db = 12 in the Handler.h file
003e ~ 003f:00 to create TABLE [table_option] of key_block_size in handler.h file of ulong Key_block_size;
Follow down to locate Forminfo_offset, which is where the table field begins.
1. Preparation of knowledge in advance, struct
Format |
C |
Python |
Number of bytes |
X |
Pad byte |
No value |
1 |
C |
Char |
string of length 1 |
1 |
B |
Signed Char |
Integer |
1 |
B |
unsigned char |
Integer |
1 |
? |
_bool |
bool |
1 |
H |
Short |
Integer |
2 |
H |
unsigned short |
Integer |
2 |
I |
Int |
Integer |
4 |
I |
unsigned int |
Integer or Long |
4 |
L |
Long |
Integer |
4 |
L |
unsigned long |
Long |
4 |
Q |
Long Long |
Long |
8 |
Q |
unsigned long long |
Long |
8 |
F |
Float |
Float |
4 |
D |
Double |
Float |
8 |
S |
Char[] |
String |
1 |
P |
Char[] |
String |
1 |
P |
void * |
Long |
|
2. Little-endian & Big-endian's understanding, x86 is generally Little-endian
The following are fixed lengths, the problem is to find Forminfo_offset, Metadata_length and Metadata_offset:
Forminfo_offset, which is the starting position of the table field, variable
Metadata_offset = forminfo_offset + forminfo_length + screens_length
metadata_length = column_count * Bytes Arrival table 1th Field distance + Metadata_offset
Forminfo_length = 288
Header_size = 64
forminfo_names_length = File location offset:0x0004 (H), 3.23 after version 3, 2 bytes
Column_count = (Forminfo_offset + 258) (H) Total number of fields, accounting for 2 bytes
Screens_length the number of bytes reached in the FormInfo field metadata, accounting for 2 bytes
Screens_length = (Forminfo_offset + 260) (H)
This is the forminfo_offset:0x3000.
metadata_offset:0x328c
metadata_length:0x3446
Positioning the 0x3446 can know the table of the 1th field position, the 2 conversion into characters, PHP, Python has a struct's pack and unpack function, C more trouble, with 0xFF as the field name delimiter:
To be continued tomorrow. Supplemental index information and comment information ...
To parse the frm file (continuous update) in order to resolve the Mysqlbing translation table field problem