ibd2sdi 是一個從 InnoDB
表空間檔案中提取序列化字典資訊 (SDI) 的工具。SDI 資料存在於所有持久性 InnoDB
表空間檔案中。
ibd2sdi 可以在每個表格檔案的表空間檔案 (*.ibd
檔案)、通用表空間檔案 (*.ibd
檔案)、系統表空間檔案 (ibdata*
檔案) 和資料字典表空間 (mysql.ibd
) 上執行。它不支援用於暫時表空間或復原表空間。
ibd2sdi 可以在執行時或伺服器離線時使用。在與 SDI 相關的 DDL 作業、ROLLBACK
作業和復原記錄清除作業期間,可能會有一小段時間,ibd2sdi 無法讀取儲存在表空間中的 SDI 資料。
ibd2sdi 會對指定表空間中的 SDI 執行未提交的讀取。不會存取重做記錄和復原記錄。
像這樣呼叫 ibd2sdi 公用程式
ibd2sdi [options] file_name1 [file_name2 file_name3 ...]
ibd2sdi 支援多檔案表空間,例如 InnoDB
系統表空間,但一次不能在一個以上的表空間上執行。對於多檔案表空間,請指定每個檔案
ibd2sdi ibdata1 ibdata2
多檔案表空間的檔案必須按照遞增頁碼的順序指定。如果兩個連續的檔案具有相同的空間 ID,則後續檔案必須從前一個檔案的最後一個頁碼 + 1 開始。
ibd2sdi 以 JSON
格式輸出 SDI (包含 id、type 和 data 欄位)。
ibd2sdi 選項
ibd2sdi 支援下列選項
--help
、-h
命令列格式 --help
類型 布林值 預設值 false
顯示說明訊息並結束。例如
Usage: ./ibd2sdi [-v] [-c <strict-check>] [-d <dump file name>] [-n] filename1 [filenames] See https://mysqldev.dev.org.tw/doc/refman/9.0/en/ibd2sdi.html for usage hints. -h, --help Display this help and exit. -v, --version Display version information and exit. -#, --debug[=name] Output debug log. See https://mysqldev.dev.org.tw/doc/refman/9.0/en/dbug-package.html -d, --dump-file=name Dump the tablespace SDI into the file passed by user. Without the filename, it will default to stdout -s, --skip-data Skip retrieving data from SDI records. Retrieve only id and type. -i, --id=# Retrieve the SDI record matching the id passed by user. -t, --type=# Retrieve the SDI records matching the type passed by user. -c, --strict-check=name Specify the strict checksum algorithm by the user. Allowed values are innodb, crc32, none. -n, --no-check Ignore the checksum verification. -p, --pretty Pretty format the SDI output.If false, SDI would be not human readable but it will be of less size (Defaults to on; use --skip-pretty to disable.) Variables (--variable-name=value) and boolean options {FALSE|TRUE} Value (after reading options) --------------------------------- ---------------------------------------- debug (No default value) dump-file (No default value) skip-data FALSE id 0 type 0 strict-check crc32 no-check FALSE pretty TRUE
--version
、-v
命令列格式 --version
類型 布林值 預設值 false
顯示版本資訊並結束。例如
ibd2sdi Ver 9.0.0 for Linux on x86_64 (Source distribution)
--debug[=
、debug_options
]-# [
debug_options
]命令列格式 --debug=options
類型 字串 預設值 [無]
列印偵錯記錄。如需偵錯選項,請參閱第 7.9.4 節,「DBUG 套件」。
ibd2sdi --debug=d:t /tmp/ibd2sdi.trace
只有在使用
WITH_DEBUG
建置 MySQL 時,此選項才可用。Oracle 提供的 MySQL 發行版二進位檔不使用此選項建置。--dump-file=
、-d
命令列格式 --dump-file=file
類型 檔案名稱 預設值 [無]
將序列化字典資訊 (SDI) 傾印到指定的傾印檔案中。如果未指定傾印檔案,則表空間 SDI 會傾印到
stdout
。ibd2sdi --dump-file=file_name ../data/test/t1.ibd
--skip-data
,-s
命令列格式 --skip-data
類型 布林值 預設值 false
跳過從序列化字典資訊 (SDI) 中檢索
data
欄位值,僅檢索id
和type
欄位值,它們是 SDI 記錄的主索引鍵。$> ibd2sdi --skip-data ../data/test/t1.ibd ["ibd2sdi" , { "type": 1, "id": 330 } , { "type": 2, "id": 7 } ]
--id=
,#
-i
#
命令列格式 --id=#
類型 整數 預設值 0
檢索符合指定資料表或資料表空間物件 ID 的序列化字典資訊 (SDI)。物件 ID 對於物件類型而言是唯一的。資料表和資料表空間物件 ID 也可在
mysql.tables
和mysql.tablespace
資料字典資料表的id
欄位中找到。如需資料字典資料表的相關資訊,請參閱第 16.1 節「資料字典結構描述」。$> ibd2sdi --id=7 ../data/test/t1.ibd ["ibd2sdi" , { "type": 2, "id": 7, "object": { "mysqld_version_id": 80003, "dd_version": 80003, "sdi_version": 1, "dd_object_type": "Tablespace", "dd_object": { "name": "test/t1", "comment": "", "options": "", "se_private_data": "flags=16417;id=2;server_version=80003;space_version=1;", "engine": "InnoDB", "files": [ { "ordinal_position": 1, "filename": "./test/t1.ibd", "se_private_data": "id=2;" } ] } } } ]
--type=
,#
-t
#
命令列格式 --type=#
類型 列舉 預設值 0
有效值 1
2
檢索符合指定物件類型的序列化字典資訊 (SDI)。針對資料表 (type=1) 和資料表空間 (type=2) 物件提供 SDI。
此範例顯示
test
資料庫中資料表空間ts1
的輸出$> ibd2sdi --type=2 ../data/test/ts1.ibd ["ibd2sdi" , { "type": 2, "id": 7, "object": { "mysqld_version_id": 80003, "dd_version": 80003, "sdi_version": 1, "dd_object_type": "Tablespace", "dd_object": { "name": "test/ts1", "comment": "", "options": "", "se_private_data": "flags=16417;id=2;server_version=80003;space_version=1;", "engine": "InnoDB", "files": [ { "ordinal_position": 1, "filename": "./test/ts1.ibd", "se_private_data": "id=2;" } ] } } } ]
由於
InnoDB
處理預設值中繼資料的方式,即使未使用DEFAULT
定義,在給定資料表欄的 ibd2sdi 輸出中,預設值仍可能存在且為非空。CREATE TABLE t1 (c VARCHAR(16) NOT NULL); CREATE TABLE t2 (c VARCHAR(16) NOT NULL DEFAULT "Sakila");
使用 ibd2sdi,我們可以看見欄
c
的default_value
為非空,且實際上在兩個資料表中都已填補至特定長度,如下所示$> ibd2sdi ../data/i/t1.ibd | grep -m1 '\"default_value\"' | cut -b34- | sed -e s/,// "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nAAAAAAAAAAA=" $> ibd2sdi ../data/i/t2.ibd | grep -m1 '\"default_value\"' | cut -b34- | sed -e s/,// "BlNha2lsYQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nAAAAAAAAAAA="
使用像是 jq 之類的 JSON 感知公用程式,可能會更容易檢查 ibd2sdi 的輸出,如下所示
$> ibd2sdi ../data/i/t1.ibd | jq '.[1]["object"]["dd_object"]["columns"][0]["default_value"]' "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nAAAAAAAAAAA=" $> ibd2sdi ../data/i/t2.ibd | jq '.[1]["object"]["dd_object"]["columns"][0]["default_value"]' "BlNha2lsYQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nAAAAAAAAAAA="
如需更多資訊,請參閱MySQL 內部文件。
--strict-check
,-c
命令列格式 --strict-check=algorithm
類型 列舉 預設值 crc32
有效值 crc32
innodb
none
指定嚴格的校驗和演算法,以驗證所讀取頁面的校驗和。選項包括
innodb
、crc32
和none
。在此範例中,指定了嚴格版本的
innodb
校驗和演算法ibd2sdi --strict-check=innodb ../data/test/t1.ibd
在此範例中,指定了嚴格版本的
crc32
校驗和演算法ibd2sdi -c crc32 ../data/test/t1.ibd
如果您未指定
--strict-check
選項,則會針對非嚴格的innodb
、crc32
和none
校驗和執行驗證。--no-check
,-n
命令列格式 --no-check
類型 布林值 預設值 false
跳過所讀取頁面的校驗和驗證。
ibd2sdi --no-check ../data/test/t1.ibd
--pretty
,-p
命令列格式 --pretty
類型 布林值 預設值 false
以 JSON 美化列印格式輸出 SDI 資料。預設啟用。如果停用,SDI 則不適合人閱讀,但大小較小。使用
--skip-pretty
停用。ibd2sdi --skip-pretty ../data/test/t1.ibd