This article original for freas_1990, reprint please indicate source: http://blog.csdn.net/freas_1990/article/details/45843615
The C version of the MySQL storage block format read Tool source code is as follows:
where MySQL block storage using big-endian bytes, so need to do a certain conversion, C language pointer power conversion method as follows:
#include <stdio.h> #include <stdlib.h>int readpage (unsigned char * page_hdr,int page_off,file *fd) {int ret =- 1;if (ret = fseek (fd,page_off,seek_set))! = 0) {//fseek error may not be caught successfully hereprintf ("Fseek failed\n"); Exit (-1);} printf ("Now from our calclation Page_off is%d\n", Page_off); ret = fread (PAGE_HDR,62,1,FD)) {printf ("read Page failed! RET is%d\n ", ret); return-1;} return 1;} int main () {unsigned char page_hdr_tmp[62];unsigned char * tmp;unsigned int page_offset = 0;unsigned short Page_type = 0;u nsigned int tab_space_id = 0;unsigned short Page_level = 0;int ret = -1;int Page_count = 0;int filesize = 0; FILE *fd;if (!freopen ("C:\\mingw\\bin\\log.txt", "w", stdout)) {printf ("log file created failed!\n");} if (! ( FD = fopen ("C:\\mingw\\bin\\payment.ibd", "RB")) {printf ("fopen failed!\n"); return-1;} if (ret = fseek (fd,0,seek_end) )! = 0) {printf ("fseek failed\n"); exit (-1);} FileSize = Ftell (FD);p rintf ("FileSize is%d\n", filesize) and while (Page_count < filesIZE/1024/16) {printf ("processing the%d [rd] page\n", page_count); if (ret = Readpage (page_hdr_tmp, page_count*16*1024, FD ) {page_count++;} else {printf ("Readpage failed!\n"); System ("pause"); exit-1;} For page_offsettmp = (unsigned char *) &page_offset;tmp[0] = page_hdr_tmp[7];tmp[1] = page_hdr_tmp[6];tmp[2] = Page_ HDR_TMP[5];TMP[3] = page_hdr_tmp[4];//for page_typetmp = (unsigned char *) &page_type;tmp[0] = page_hdr_tmp[25];tmp[ 1] = page_hdr_tmp[24];//for tab_space_idtmp = (unsigned char *) &tab_space_id;tmp[0] = page_hdr_tmp[37];tmp[1] = Page_ HDR_TMP[36];TMP[2] = page_hdr_tmp[35];tmp[3] = page_hdr_tmp[34];//for page_leveltmp = (unsigned char *) &page_level; Tmp[0] = page_hdr_tmp[61];tmp[1] = page_hdr_tmp[60];p rintf ("Page_offset is%d\n", Page_offset);p rintf ("Page_type is%x\ n ", Page_type);p rintf (" tab_space_id is%x\n ", tab_space_id);p rintf (" Page_level is%x\n\n ", page_level);} Fclose (FD); System ("pause"); return 0;}
We open the program output log to see that the information is as follows:
FileSize is 10485760processing the 0 [Rd] Pagenow from our calclation Page_off are 0page_offset is 0page_type _ID is 11page_level are bprocessing the 1 [rd] Pagenow from our calclation Page_off are 16384page_offset is a 5t AB_SPACE_ID is 11page_level are 0processing the 2 [rd] Pagenow from We calclation Page_off is 32768page_offset PE is 3tab_space_id are 11page_level are 0processing the 3 [rd] Pagenow from our calclation Page_off are 49152page_offset is 3page_type is 45bftab_space_id are 11page_level is 0
Where the Page_type 45BF represents the index node. The Page_level is 0, meaning that the index node has a level of 0.
When the 75th [RD] Block is reached, all blocks are blank blocks.
processing the [rd] Pagenow from our calclation Page_off are 1212416page_offset is 74page_type are 45bftab_space_id is 11 Page_level is 0processing the (RD) Pagenow from our calclation Page_off are 1228800page_offset is 0page_type CE_ID is 0page_level is 0processing the (RD) Pagenow from our calclation Page_off are 1245184page_offset is 0page_type I S 0tab_space_id is 0page_level is 0
The tested IBD file is a MySQL 5.6 payment.ibd under the Sakila library.
C-language version MySQL memory block (page) format reading tool (source code)