MySQL学习笔记-手动数据备份恢复(ibd文件)

1.备份的数据文件

数据文件默认路径为:C:\ProgramData\MySQL\MySQL Server 8.0\Data

需要保存对应数据下对应数据库的所有“.ibd”文件

2.删除旧的数据(取消表与idb文件的关联):、

//指令为 alter table table1 discard tablespace;

//以下声明是用于配置mysql数据,以在数据表有数据关联的情况下仍然可以取消关联
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

alter table pgx.aboutlist discard tablespace;
alter table pgx.channellist discard tablespace;
alter table pgx.customer discard tablespace;
alter table pgx.eventlog discard tablespace;
alter table pgx.genotypelist discard tablespace;
alter table pgx.hospital discard tablespace;
alter table pgx.item discard tablespace;
alter table pgx.itempackage discard tablespace;
alter table pgx.itemtypelist discard tablespace;
alter table pgx.medicinesuggested discard tablespace;
alter table pgx.packageaboutlist discard tablespace;
alter table pgx.record_about discard tablespace;
alter table pgx.record_data discard tablespace;
alter table pgx.record_file discard tablespace;
alter table pgx.record_item discard tablespace;
alter table pgx.record_itempackage discard tablespace;
alter table pgx.record_layout discard tablespace;
alter table pgx.record_log discard tablespace;
alter table pgx.record_packageabout discard tablespace;
alter table pgx.record_subitem discard tablespace;
alter table pgx.relatedgenelist discard tablespace;
alter table pgx.result_combination discard tablespace;
alter table pgx.result_starcells discard tablespace;
alter table pgx.result_suggests discard tablespace;
alter table pgx.resultslist discard tablespace;
alter table pgx.rslist discard tablespace;
alter table pgx.sampletypelist discard tablespace;
alter table pgx.subitem discard tablespace;
alter table pgx.subitemtypelist discard tablespace;
alter table pgx.user discard tablespace;


//以下是重新配置相关参数
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

注意:删除表时需要表存在,若有表不存在时执行,会报“Incorrect key file for table”错误,需要重新创建表,然后重新删除数据。

3.将备份的所有idb文件拷贝到目标替换的数据库文件夹内

 4.重新关联idb文件

//使用的指令为:alter table table1 import tablespace;

alter table pgx.aboutlist import tablespace;
alter table pgx.channellist import tablespace;
alter table pgx.customer import tablespace;
alter table pgx.eventlog import tablespace;
alter table pgx.genotypelist import tablespace;
alter table pgx.hospital import tablespace;
alter table pgx.item import tablespace;
alter table pgx.itempackage import tablespace;
alter table pgx.itemtypelist import tablespace;
alter table pgx.medicinesuggested import tablespace;
alter table pgx.packageaboutlist import tablespace;
alter table pgx.record_about import tablespace;
alter table pgx.record_data import tablespace;
alter table pgx.record_file import tablespace;
alter table pgx.record_item import tablespace;
alter table pgx.record_itempackage import tablespace;
alter table pgx.record_layout import tablespace;
alter table pgx.record_log import tablespace;
alter table pgx.record_packageabout import tablespace;
alter table pgx.record_subitem import tablespace;
alter table pgx.relatedgenelist import tablespace;
alter table pgx.result_combination import tablespace;
alter table pgx.result_starcells import tablespace;
alter table pgx.result_suggests import tablespace;
alter table pgx.resultslist import tablespace;
alter table pgx.rslist import tablespace;
alter table pgx.sampletypelist import tablespace;
alter table pgx.subitem import tablespace;
alter table pgx.subitemtypelist import tablespace;
alter table pgx.user import tablespace;

### 使用 `ibd2sql` 进行 MySQL IBD 文件的数据恢复 #### 准备工作 为了成功使用 `ibd2sql` 工具进行数据恢复,需准备如下环境和文件- 安装 Python 3.x 及其依赖库。 - 获取目标版本的 MySQL 实例运行权限。 - 备份待恢复的 `.ibd` 文件及其对应的 `.frm` 文件(如果适用)。对于较新版本的 MySQL (8.0+),`.frm` 文件可能不再存在。 #### 执行过程 通过 `ibd2sql` 工具解析并转换 IBD 文件SQL 脚本的过程涉及几个关键步骤。下面是一个具体的例子来说明这一流程[^2]。 假设有一个名为 `ddcw_alltype_table` 的表,在不同版本之间迁移时遇到问题,则可以按照以下方式操作: 1. **提取 DDL** 对于 MySQL 5.6/5.7 版本中的表结构定义(.frm),可以通过 `dbsake frmdump` 命令导出创建该表所需的 SQL 语句,并将其导入至更高版本的 MySQL 中作为元数据源: ```bash dbsake frmdump test.frm | mysql -u root -p ``` 2. **调用 ibd2sql 解析 IBD 文件** 接下来利用 `ibd2sql` 将旧版 MySQL 表空间(`.ibd`)转成可读取的 SQL 插入语句。这里指定两个路径参数分别指向新版与旧版的同名表格的空间文件位置: ```bash python3 main.py \ --sdi-table /your_mysql8_path/ddcw_alltype_table.ibd \ /your_mysql5_path/ddcw_alltype_table.ibd \ --sql --mysql5 ``` 上述命令会生成一系列 INSERT INTO ... VALUES (...) 形式的SQL指令,这些指令可以直接应用于新的数据库环境中完成数据加载。 请注意,当面对非常大尺寸或是已经遭受一定程度物理损伤的 IBD 文件时,整个过程中可能会遭遇性能瓶颈或者是无法完全重建原始记录的情况。因此建议提前做好充分测试以及风险评估[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鱼听禅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值