diff --git "a/content/blog/2024-04-30/MySQL8 InnoDB \346\225\260\346\215\256\346\201\242\345\244\215.md" "b/content/blog/2024-04-30/MySQL8 InnoDB \346\225\260\346\215\256\346\201\242\345\244\215.md" new file mode 100644 index 0000000..65959b2 --- /dev/null +++ "b/content/blog/2024-04-30/MySQL8 InnoDB \346\225\260\346\215\256\346\201\242\345\244\215.md" @@ -0,0 +1,55 @@ +--- +title: "MySQL8 InnoDB 数据恢复" +description: "" +lead: "" +date: 2024-04-30T08:51:56Z +lastmod: 2024-04-30T08:51:56Z +draft: false +weight: 50 +contributors: [clannadzsy] +url: "/blog/429417542/" +--- + +# MySQL8 InnoDB 数据恢复 + +~~ 硬盘突然损坏, 数据侥幸得以导出 ~~ + +1. 前提条件 + + 1.1 提前创建好表的结构 `sql`, 执行 `sql` 恢复表的结构 + + 1.2 然后使用 `table_name.ibd `的文件覆盖, 最好是一张表恢复成功再覆盖下一张 + +2. 找到 `mysql` 安装目录文件夹, 进入需要恢复的数据库的`database_name`文件夹 + +3. 将 `table_name.ibd` 复制进去, 修改文件为所属为 `mysql` + + ```bash + sudo chown mysql:mysql .ibd + ``` + +4. ```bach + mysql -u root -p + ``` + +5. ```mysql + user ; + ``` + +6. ```mysql + ALTER TABLE DISCARD TABLESPACE; + ``` + +7. ```mysql + ALTER TABLE IMPORT TABLESPACE; + ``` + +8. ```mysql + # 验证数据是否恢复成功 + select * from crocodile_user limit 1; + ``` + + + + +​ \ No newline at end of file