MySQL 数据恢复方法(二)

使用场景

InnoDB数据文件损坏,数据库无法启动,且无数据备份的情况下,进行数据恢复。
仅对MySQL InnoDB存储引擎数据文件有效。

所需资源

1.  InnoDB 数据文件
2.  可获取表结构的 mysql server

操作说明

1. 使用 percona-data-recovery-tool-for-innodb 构建恢复工具。主要构建出2个工具,page_parser & constraints_parser。

2. 使用 page_parser 提取需要恢复的数据页,会在当前目录下生成 pages-$timestamp 数据文件目录
[root@mysql percona-data-recovery-tool-for-innodb]# page_parser -5 -f /path/to/ibdata1

##命令使用方法
[root@mysql percona-data-recovery-tool-for-innodb]# ./page_parser -h
Error: Usage: ./page_parser -4|-5 [-dDhcCV] -f <innodb_datafile> [-T N:M] [-s size] [-t size]
  Where
    -h  -- Print this help
    -V  -- Print debug information
    -d  -- Process only those pages which potentially could have deleted records (default = NO)
    -s size -- Amount of memory used for disk cache (allowed examples 1G 10M). Default 100M
    -T  -- retrieves only pages with index id = NM (N - high word, M - low word of id)
    -c  -- count pages in the tablespace and group them by index id
    -C  -- count pages in the tablespace and group them by index id (and ignore too high/zero indexes)
    -t  size -- Size of InnoDB tablespace to scan. Use it only if the parser can't determine it by himself.

3.  生成相关表定义文件,并重新编译构建 constraints_parser 工具(需要连接数据库,有表结构即可)
[root@mysql percona-data-recovery-tool-for-innodb]# ./create_defs.pl --host=$db_host --user=$user --password=$pass --db=$database --table=$table > include/table_defs.h

[root@mysql percona-data-recovery-tool-for-innodb]# make

4.  从 pages-$timestamp 目录提取数据,可以导出到文件
[root@mysql percona-data-recovery-tool-for-innodb]# ./constraints_parser -5 -f pages-1493793157/FIL_PAGE_INDEX/0-22/0-00000003.page > datafile
LOAD DATA INFILE '/root/percona-data-recovery-tool-for-innodb/dumps/default/test' REPLACE INTO TABLE `test` FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '"' LINES STARTING BY 'test\t' (id, name);

[root@mysql percona-data-recovery-tool-for-innodb]# cat datafile
test    1       "test"
test    2       "test2"
test    3       "test3"
test    4       "test4"

5. 进行数据导入恢复
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值