8.0.12-debug
xxd
Mysql
數據頁存儲, 能夠參見 https://segmentfault.com/a/1190000037436803
2.系統表是什麼? 跟本身建立的表有何不一樣?html
mysql.schemata
,mysql.tables
, mysql.indexes
3.DD存儲在哪些地方?python
這裏是針對Mysql 8的數據字典,mysql
Mysql 8以前, 數據字典存儲結構以下圖,sql
從圖中能夠看出, DD信息存儲在多個地方,數據庫
這種存儲方式存在如下問題:json
Mysql 8 對數據字典進行了從新設計, 而且使用InnoDB存儲,segmentfault
SET SESSION debug='+d,skip_dd_table_access_check'; SELECT name, schema_id, hidden, type FROM mysql.tables where schema_id=1 AND hidden='System';
能夠看到DD中存儲了不少系統表,服務器
+------------------------------+-----------+--------+------------+ | name | schema_id | hidden | type | +------------------------------+-----------+--------+------------+ | catalogs | 1 | System | BASE TABLE | | character_sets | 1 | System | BASE TABLE | | collations | 1 | System | BASE TABLE | | columns | 1 | System | BASE TABLE | | dd_properties | 1 | System | BASE TABLE | | events | 1 | System | BASE TABLE | | index_stats | 1 | System | BASE TABLE | | indexes | 1 | System | BASE TABLE | | schemata | 1 | System | BASE TABLE | | tables | 1 | System | BASE TABLE | | tablespace_files | 1 | System | BASE TABLE | | tablespaces | 1 | System | BASE TABLE | +------------------------------+-----------+--------+------------+
2.經過 ibd2sdi
工具查看工具
ibd2sdi test.ibd
2.SDI如何組織?學習
3.SDI舉例
{ "mysqld_version_id":80012, "dd_version":80012, "sdi_version":1, "dd_object_type":"Table", "dd_object":{ "name":"x", "columns":[ { "name":"id", "type":4, ... }, { "name":"DB_TRX_ID", "type":10, ... }, { "name":"DB_ROLL_PTR", "type":9, ... } ], ... "indexes":[ { "name":"PRIMARY", "hidden":false, ... } ], ... } }
上文中, 咱們說過在每一個表的獨立表空間中, 存儲了這個表相關的DD對象序列化後的信息。在這一節, 咱們學習如何查看SDI信息。
CREATE TABLE `x` ( `id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
2.查看這表的獨立表空間文件, 經過 xxd x.ibd x.txt
查看這個表空間的數據頁, 這裏咱們主要看第4頁, 這1頁存儲了這個表相關的數據字典序列化信息,
000c000: 723e 3b3c 0000 0003 ffff ffff ffff ffff r>;<............ 000c010: 0000 0000 0128 06fc 45bd 0000 0000 0000 .....(..E....... 000c020: 0000 0000 0004 0002 04d2 8004 0000 0000 ................ 000c030: 0172 0001 0001 0002 0000 0000 0000 0000 .r.............. 000c040: 0000 ffff ffff ffff ffff 0000 0004 0000 ................ 000c050: 0002 00f2 0000 0004 0000 0002 0032 0100 .............2.. 000c060: 0201 0f69 6e66 696d 756d 0003 000b 0000 ...infimum...... 000c070: 7375 7072 656d 756d cb80 0000 10ff f100 supremum........ 000c080: 0000 0200 0000 0000 0000 0900 0000 0016 ................ ........ ........ 000fff0: 0000 0000 0070 0063 723e 3b3c 0128 06fc .....p.cr>;<.(..
對於一個表空間而言, 可能會有多個數據字典對象, 這些對象序列化後會以B+樹的方式組織, 咱們看一下具體的存儲結構,
總體頁存儲結構:
咱們再看下每一個記錄的具體存儲:
記錄說明:
存儲結構以下圖所示,
3.SDI記錄遍歷流程
注意: 遊標以每一個記錄的內容開始, 例如最小記錄的開始位置爲00c063, 而不是00c05e。計算的下一個記錄位置, 也是內容開始的位置。
4.如何查看SDI壓縮後的數據
#!/usr/bin/env python # -*- coding=utf-8 -*- # import os import sys import json import time import datetime import hashlib import zlib reload(sys) sys.setdefaultencoding("utf-8") def help(): f = open("./test.data") l = f.readline() d = zlib.compress(l) f2 = open("./tmp.data", 'w+') f2.write(d) help()
0xffff fffe
是data dicitonary的表空間, 也就是mysql.ibd0xffff fffd
是臨時表空間, 也就是ibtmp1.ibd0xffff fffc
, 0xffff fff0
]是爲日誌準備的0xffff ffef
, 0xffff ff70
]是undo log0x0000 0002
, 0xffff ff6f
]是能夠正常使用的表空間sys/sys_config
表空間2.DD表空間存儲
2.思考