最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

mysql8.0?.ibd文件恢復(fù)表結(jié)構(gòu)的實現(xiàn)

 更新時間:2024年10月17日 11:45:40   作者:子非花  
本文主要介紹了mysql8.0?.ibd文件恢復(fù)表結(jié)構(gòu)的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

今天早上啟動了 phpstudy 軟件中的 MySQL 8.0 數(shù)據(jù)庫時,發(fā)現(xiàn)它啟動后約過了 3 秒就自行關(guān)閉了。接著又自動啟動然后再次關(guān)閉,似乎陷入了一個“開-閉-開”的循環(huán)。這導(dǎo)致我無法正常使用數(shù)據(jù)庫。在嘗試修改配置文件和端口號無果后,我決定卸載數(shù)據(jù)庫并重新安裝。根據(jù)之前的經(jīng)驗,我直接備份了 MySQL 安裝路徑下的 data 文件夾。之前使用的是 MySQL 5.7 版本,直接備份 data 文件夾下的文件可以保留數(shù)據(jù)庫的庫名、表名、字段、索引等信息。在重新安裝后,將之前備份的數(shù)據(jù)直接導(dǎo)入新的數(shù)據(jù)庫的 data 文件夾下也是順利的,使用像 Navicat 這樣的 MySQL 可視化工具可以看到表名和表結(jié)構(gòu)。但是在 MySQL 8.0 及以上版本,情況就有所不同了,這導(dǎo)致后續(xù)出現(xiàn)了很多問題。

在 MySQL 8.0 中,數(shù)據(jù)庫文件存儲在 data 文件夾中,每個目錄代表一個數(shù)據(jù)庫。在每個數(shù)據(jù)庫目錄下,有多個 .ibd 文件,每個 .ibd 文件對應(yīng)一張表,文件名即表名。.ibd 文件是 MySQL 的表數(shù)據(jù)文件,而在 MySQL 8 之前,表定義存儲在 .frm 后綴的文件中,表數(shù)據(jù)和表索引存儲在 .ibd 文件中。所有這些文件都在 MySQL 的 data 目錄下,即數(shù)據(jù)庫名所在的目錄中。閑來無事記錄一下。

查看mysql數(shù)據(jù)庫data文件夾路徑:

show variables like ‘%datadir%' 

.ibd文件是以二進(jìn)制形式存儲的,這個時候想要查看存儲內(nèi)容需要用mysql8自帶的 ibd2sdi命令 進(jìn)行解析,首先查看是否能執(zhí)行這個命令,找不到命令或者不存在就需要配置系統(tǒng)環(huán)境變量了,起初我嘗試到phpstudy環(huán)境下的mysql8的安裝目錄找bin目錄,看看能否執(zhí)行ibd2sdi命令,不行于是我到官網(wǎng)下載一個mysql在本地安裝,接著配置環(huán)境變量。

ibd2sdi 命令:

G:\PhpStudy\phpstudy_pro\Extensions\MySQL8.0.12\data\ruibaiqiche>ibd2sdi --dump-file rb_position.txt rb_position.ibd

解析內(nèi)容:

["ibd2sdi"
,
{
	"type": 1,
	"id": 1929,
	"object":
		{
    "mysqld_version_id": 80012,
    "dd_version": 80012,
    "sdi_version": 1,
    "dd_object_type": "Table",
    "dd_object": {
        "name": "rb_position",
        "mysql_version_id": 80012,
        "created": 20231214074915,
        "last_altered": 20231214074915,
        "hidden": 1,
        "options": "avg_row_length=0;key_block_size=0;keys_disabled=0;pack_record=1;stats_auto_recalc=0;stats_sample_pages=0;",
        "columns": [
            {
                "name": "id",
                "type": 4,
                "is_nullable": false,
                "is_zerofill": false,
                "is_unsigned": false,
                "is_auto_increment": true,
                "is_virtual": false,
                "hidden": 1,
                "ordinal_position": 1,
                "char_length": 11,
                "numeric_precision": 10,
                "numeric_scale": 0,
                "numeric_scale_null": false,
                "datetime_precision": 0,
                "datetime_precision_null": 1,
                "has_no_default": false,
                "default_value_null": false,
                "srs_id_null": true,
                "srs_id": 0,
                "default_value": "AAAAAA==",
                "default_value_utf8_null": true,
                "default_value_utf8": "",
                "default_option": "",
                "update_option": "",
                "comment": "ID",
                "generation_expression": "",
                "generation_expression_utf8": "",
                "options": "interval_count=0;",
                "se_private_data": "table_id=2219;",
                "column_key": 2,
                "column_type_utf8": "int(11)",
                "elements": [],
                "collation_id": 8,
                "is_explicit_collation": false
            },
            {
                "name": "position",
                "type": 16,
                "is_nullable": true,
                "is_zerofill": false,
                "is_unsigned": false,
                "is_auto_increment": false,
                "is_virtual": false,
                "hidden": 1,
                "ordinal_position": 2,
                "char_length": 400,
                "numeric_precision": 0,
                "numeric_scale": 0,
                "numeric_scale_null": true,
                "datetime_precision": 0,
                "datetime_precision_null": 1,
                "has_no_default": false,
                "default_value_null": true,
                "srs_id_null": true,
                "srs_id": 0,
                "default_value": "",
                "default_value_utf8_null": true,
                "default_value_utf8": "",
                "default_option": "",
                "update_option": "",
                "comment": "職位名稱",
                "generation_expression": "",
                "generation_expression_utf8": "",
                "options": "interval_count=0;",
                "se_private_data": "table_id=2219;",
                "column_key": 1,
                "column_type_utf8": "varchar(100)",
                "elements": [],
                "collation_id": 45,
                "is_explicit_collation": false
            },
            {
                "name": "createtime",
                "type": 19,
                "is_nullable": true,
                "is_zerofill": false,
                "is_unsigned": false,
                "is_auto_increment": false,
                "is_virtual": false,
                "hidden": 1,
                "ordinal_position": 3,
                "char_length": 19,
                "numeric_precision": 0,
                "numeric_scale": 0,
                "numeric_scale_null": true,
                "datetime_precision": 0,
                "datetime_precision_null": 0,
                "has_no_default": false,
                "default_value_null": true,
                "srs_id_null": true,
                "srs_id": 0,
                "default_value": "",
                "default_value_utf8_null": true,
                "default_value_utf8": "",
                "default_option": "",
                "update_option": "",
                "comment": "",
                "generation_expression": "",
                "generation_expression_utf8": "",
                "options": "interval_count=0;",
                "se_private_data": "table_id=2219;",
                "column_key": 1,
                "column_type_utf8": "datetime",
                "elements": [],
                "collation_id": 8,
                "is_explicit_collation": false
            },
            {
                "name": "updatetime",
                "type": 19,
                "is_nullable": true,
                "is_zerofill": false,
                "is_unsigned": false,
                "is_auto_increment": false,
                "is_virtual": false,
                "hidden": 1,
                "ordinal_position": 4,
                "char_length": 19,
                "numeric_precision": 0,
                "numeric_scale": 0,
                "numeric_scale_null": true,
                "datetime_precision": 0,
                "datetime_precision_null": 0,
                "has_no_default": false,
                "default_value_null": true,
                "srs_id_null": true,
                "srs_id": 0,
                "default_value": "",
                "default_value_utf8_null": true,
                "default_value_utf8": "",
                "default_option": "",
                "update_option": "",
                "comment": "",
                "generation_expression": "",
                "generation_expression_utf8": "",
                "options": "interval_count=0;",
                "se_private_data": "table_id=2219;",
                "column_key": 1,
                "column_type_utf8": "datetime",
                "elements": [],
                "collation_id": 8,
                "is_explicit_collation": false
            },
            {
                "name": "deletetime",
                "type": 19,
                "is_nullable": true,
                "is_zerofill": false,
                "is_unsigned": false,
                "is_auto_increment": false,
                "is_virtual": false,
                "hidden": 1,
                "ordinal_position": 5,
                "char_length": 19,
                "numeric_precision": 0,
                "numeric_scale": 0,
                "numeric_scale_null": true,
                "datetime_precision": 0,
                "datetime_precision_null": 0,
                "has_no_default": false,
                "default_value_null": true,
                "srs_id_null": true,
                "srs_id": 0,
                "default_value": "",
                "default_value_utf8_null": true,
                "default_value_utf8": "",
                "default_option": "",
                "update_option": "",
                "comment": "",
                "generation_expression": "",
                "generation_expression_utf8": "",
                "options": "interval_count=0;",
                "se_private_data": "table_id=2219;",
                "column_key": 1,
                "column_type_utf8": "datetime",
                "elements": [],
                "collation_id": 8,
                "is_explicit_collation": false
            },
            {
                "name": "DB_TRX_ID",
                "type": 10,
                "is_nullable": false,
                "is_zerofill": false,
                "is_unsigned": false,
                "is_auto_increment": false,
                "is_virtual": false,
                "hidden": 2,
                "ordinal_position": 6,
                "char_length": 6,
                "numeric_precision": 0,
                "numeric_scale": 0,
                "numeric_scale_null": true,
                "datetime_precision": 0,
                "datetime_precision_null": 1,
                "has_no_default": false,
                "default_value_null": true,
                "srs_id_null": true,
                "srs_id": 0,
                "default_value": "",
                "default_value_utf8_null": true,
                "default_value_utf8": "",
                "default_option": "",
                "update_option": "",
                "comment": "",
                "generation_expression": "",
                "generation_expression_utf8": "",
                "options": "",
                "se_private_data": "table_id=2219;",
                "column_key": 1,
                "column_type_utf8": "",
                "elements": [],
                "collation_id": 63,
                "is_explicit_collation": false
            },
            {
                "name": "DB_ROLL_PTR",
                "type": 9,
                "is_nullable": false,
                "is_zerofill": false,
                "is_unsigned": false,
                "is_auto_increment": false,
                "is_virtual": false,
                "hidden": 2,
                "ordinal_position": 7,
                "char_length": 7,
                "numeric_precision": 0,
                "numeric_scale": 0,
                "numeric_scale_null": true,
                "datetime_precision": 0,
                "datetime_precision_null": 1,
                "has_no_default": false,
                "default_value_null": true,
                "srs_id_null": true,
                "srs_id": 0,
                "default_value": "",
                "default_value_utf8_null": true,
                "default_value_utf8": "",
                "default_option": "",
                "update_option": "",
                "comment": "",
                "generation_expression": "",
                "generation_expression_utf8": "",
                "options": "",
                "se_private_data": "table_id=2219;",
                "column_key": 1,
                "column_type_utf8": "",
                "elements": [],
                "collation_id": 63,
                "is_explicit_collation": false
            }
        ],
        "schema_ref": "ruibaiqiche",
        "se_private_id": 2219,
        "engine": "InnoDB",
        "comment": "職位表",
        "se_private_data": "autoinc=0;version=2;",
        "row_format": 2,
        "partition_type": 0,
        "partition_expression": "",
        "partition_expression_utf8": "",
        "default_partitioning": 0,
        "subpartition_type": 0,
        "subpartition_expression": "",
        "subpartition_expression_utf8": "",
        "default_subpartitioning": 0,
        "indexes": [
            {
                "name": "PRIMARY",
                "hidden": false,
                "is_generated": false,
                "ordinal_position": 1,
                "comment": "",
                "options": "flags=0;",
                "se_private_data": "id=1732;root=4;space_id=1162;table_id=2219;trx_id=153333;",
                "type": 1,
                "algorithm": 2,
                "is_algorithm_explicit": false,
                "is_visible": true,
                "engine": "InnoDB",
                "elements": [
                    {
                        "ordinal_position": 1,
                        "length": 4,
                        "order": 2,
                        "column_opx": 0
                    },
                    {
                        "ordinal_position": 2,
                        "length": 4294967295,
                        "order": 2,
                        "column_opx": 5
                    },
                    {
                        "ordinal_position": 3,
                        "length": 4294967295,
                        "order": 2,
                        "column_opx": 6
                    },
                    {
                        "ordinal_position": 4,
                        "length": 4294967295,
                        "order": 2,
                        "column_opx": 1
                    },
                    {
                        "ordinal_position": 5,
                        "length": 4294967295,
                        "order": 2,
                        "column_opx": 2
                    },
                    {
                        "ordinal_position": 6,
                        "length": 4294967295,
                        "order": 2,
                        "column_opx": 3
                    },
                    {
                        "ordinal_position": 7,
                        "length": 4294967295,
                        "order": 2,
                        "column_opx": 4
                    }
                ],
                "tablespace_ref": "ruibaiqiche/rb_position"
            }
        ],
        "foreign_keys": [],
        "partitions": [],
        "collation_id": 45
    }
}
}
,
{
	"type": 2,
	"id": 1167,
	"object":
		{
    "mysqld_version_id": 80012,
    "dd_version": 80012,
    "sdi_version": 1,
    "dd_object_type": "Tablespace",
    "dd_object": {
        "name": "ruibaiqiche/rb_position",
        "comment": "",
        "options": "",
        "se_private_data": "flags=16417;id=1162;server_version=80012;space_version=1;",
        "engine": "InnoDB",
        "files": [
            {
                "ordinal_position": 1,
                "filename": ".\\ruibaiqiche\\rb_position.ibd",
                "se_private_data": "id=1162;"
            }
        ]
    }
}
}
]

后面想要恢復(fù)數(shù)據(jù)庫中的表結(jié)構(gòu)的話,只能看解析后的字段名進(jìn)行創(chuàng)建表了。解析后的.idb文件是一個json格式的數(shù)據(jù),再此基礎(chǔ)上key值基本不變,可以用代碼實現(xiàn)獲取表名和字段名再拼接成SQL語句,接著再拿到數(shù)據(jù)庫中進(jìn)行創(chuàng)建表。

function test(){
        // 獲取傳入的json
        //$data = $this->request->param();
        // 替換為你的 JSON 數(shù)據(jù)
        $jsonData = 'YOUR_JSON_DATA_HERE';
        // 解析 JSON 數(shù)據(jù)
        $data = json_decode($jsonData, true);
        // 提取表名和字段信息
        $tableName = $data[1]['object']['dd_object']['name'];
        $columns = $data[1]['object']['dd_object']['columns'];
        // 構(gòu)建創(chuàng)建表的 SQL 查詢語句
        $sql = "CREATE TABLE $tableName (";

        foreach ($columns as $column) {
            $columnName = $column['name'];
            // 如果字段名不是 DB_TRX_ID 和 DB_ROLL_PTR,則構(gòu)建該字段的 SQL
            if ($columnName !== 'DB_TRX_ID' && $columnName !== 'DB_ROLL_PTR' && $columnName !== 'DB_ROW_ID') {
                $columnType = $column['column_type_utf8'];
                $isNullable = $column['is_nullable'] ? 'NULL' : 'NOT NULL';
                $default = ($column['default_value_null'] || $column['default_value_utf8_null']) ? '' : "DEFAULT '{$column['default_value']}'";

                // 構(gòu)建列的注釋,如果注釋為空,不包含 COMMENT 部分
                $comment = isset($column['comment']) && !empty($column['comment']) ? "COMMENT '{$column['comment']}'" : '';

                // 構(gòu)建列的 SQL
                $sql .= "$columnName $columnType $isNullable $default $comment, ";
            }
        }
        // 去除最后的逗號和空格
        $sql = rtrim($sql, ', ') . ");";
        echo $sql;
    }

到此這篇關(guān)于mysql8.0 .ibd文件恢復(fù)表結(jié)構(gòu)的實現(xiàn)的文章就介紹到這了,更多相關(guān)mysql .ibd文件恢復(fù)表結(jié)構(gòu)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

  • MySQL低權(quán)限提權(quán)的方法

    MySQL低權(quán)限提權(quán)的方法

    在MySQL中,低權(quán)限提權(quán)是一種常見的需求,低權(quán)限用戶通過利用漏洞、存儲過程、用戶定義函數(shù)(UDF)和觸發(fā)器(Trigger)等技術(shù)手段進(jìn)行權(quán)限提升,本文就來介紹一下,感興趣的可以了解一下
    2024-09-09
  • MySQL數(shù)據(jù)庫事務(wù)與鎖深入分析

    MySQL數(shù)據(jù)庫事務(wù)與鎖深入分析

    這篇文章主要介紹了MySQL數(shù)據(jù)庫事務(wù)與鎖深入分析,內(nèi)容介紹的非常詳細(xì),有對這方面不懂的同學(xué)可以跟著小編一起研究下吧
    2020-12-12
  • MySQL Union合并查詢數(shù)據(jù)及表別名、字段別名用法分析

    MySQL Union合并查詢數(shù)據(jù)及表別名、字段別名用法分析

    這篇文章主要介紹了MySQL Union合并查詢數(shù)據(jù)及表別名、字段別名用法,結(jié)合實例形式較為詳細(xì)的分析了mysql使用Union合并連接查詢數(shù)據(jù)以及使用as實現(xiàn)表別名與字段別名操作,需要的朋友可以參考下
    2018-06-06
  • MySQL 如何查找刪除重復(fù)行

    MySQL 如何查找刪除重復(fù)行

    對MySQL 如何查找刪除重復(fù)行好奇得小伙伴想必也知道MySQL 操作刪除重復(fù)行,難免有時會需要查看被刪除的重行,今天小編就來給大家詳解,感興趣的小伙伴可以參考下面的文章內(nèi)容
    2021-09-09
  • mysql 實現(xiàn)互換表中兩列數(shù)據(jù)方法簡單實例

    mysql 實現(xiàn)互換表中兩列數(shù)據(jù)方法簡單實例

    這篇文章主要介紹了mysql 實現(xiàn)互換表中兩列數(shù)據(jù)方法簡單實例的相關(guān)資料,需要的朋友可以參考下
    2016-10-10
  • 一文分享10個常用的MySQL高級用法

    一文分享10個常用的MySQL高級用法

    MySQL?有很多高級但實用的功能,能讓你的查詢變得更簡潔、更高效,今天分享?10?個我在工作中經(jīng)常使用的?SQL?技巧,不用死記硬背,掌握了就能立刻提升你的數(shù)據(jù)庫操作水平
    2025-12-12
  • MySQL中使用group by 是總是出現(xiàn)1055的錯誤(推薦)

    MySQL中使用group by 是總是出現(xiàn)1055的錯誤(推薦)

    這篇文章主要介紹了MySQL中使用group by 是總是出現(xiàn)1055的錯誤,小編通過查閱相關(guān)資料才把問題解決,今天小編記錄下分享到腳本之家平臺,需要的朋友可以參考下
    2020-02-02
  • Mysql InnoDB和MyISAM區(qū)別原理解析

    Mysql InnoDB和MyISAM區(qū)別原理解析

    這篇文章主要介紹了Mysql InnoDB和MyISAM區(qū)別原理解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-10-10
  • mysql5.6建立索引報錯1709問題及解決

    mysql5.6建立索引報錯1709問題及解決

    這篇文章主要介紹了mysql5.6建立索引報錯1709問題及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • DDL數(shù)據(jù)庫與表的創(chuàng)建和管理深入講解使用教程

    DDL數(shù)據(jù)庫與表的創(chuàng)建和管理深入講解使用教程

    這篇文章主要介紹了DDL數(shù)據(jù)庫與表的創(chuàng)建和管理,系統(tǒng)架構(gòu)的層面來看,數(shù)據(jù)庫從大到小依次是數(shù)據(jù)庫服務(wù)器(上面安裝了DBMS和數(shù)據(jù)庫)、數(shù)據(jù)庫(也稱database或者schema)、數(shù)據(jù)表、數(shù)據(jù)表的行與列
    2023-04-04

最新評論

定襄县| SHOW| 达孜县| 凤城市| 曲阜市| 英吉沙县| 钦州市| 祁东县| 涟水县| 行唐县| 峡江县| 丹凤县| 壤塘县| 重庆市| 奇台县| 孝感市| 营山县| 龙陵县| 平凉市| 肥西县| 兴仁县| 廊坊市| 灵寿县| 互助| 东莞市| 天峨县| 赤壁市| 永安市| 西平县| 河曲县| 天全县| 达拉特旗| 新化县| 明溪县| 凤台县| 深州市| 周口市| 曲麻莱县| 大冶市| 花莲县| 中西区|