在另外一个机器上准备测试数据,并传输到dbadb05机器的/mysql/backup/reco/位置下。
开始尝试恢复数据
一、使用mysqlfrm获取表结构信息及DDL语句。

[mysql@dbadb05 reco]$ ll
total
-rw-r----- mysql mysql Aug : t.frm
-rw-r----- mysql mysql Aug : t.ibd
[mysql@dbadb05 reco]$ mysqlfrm t.frm --basedir=/mysql/mysql --port= --show-stats --verbose
# Starting the spawned server on port ... done.
# Reading .frm files
#
# Reading the t.frm file.
#
# CREATE statement for t.frm:
# CREATE TABLE `t` (
`a` int() DEFAULT NULL,
`b` int() DEFAULT NULL,
`c` varchar() DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 # File Statistics:
# Last Modified : Mon Aug ::
# Creation Time : Mon Aug ::
# Last Accessed : Mon Aug ::
# Mode :
# Size : # Table Statistics:
# Engine : HEAP
# frm Version :
# MySQL Version : 5.7.
# frm File_Version :
# IO_SIZE :
# Def Partition Engine : None #...done.

二、使用第一步中恢复的DDL语句创建表,并discard tablespace

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| syk |
| sys |
+--------------------+
5 rows in set (0.00 sec) mysql> create database reco;
Query OK, 1 row affected (0.00 sec) mysql> use reco;
Database changed
mysql> CREATE TABLE `t` (
-> `a` int(11) DEFAULT NULL,
-> `b` int(11) DEFAULT NULL,
-> `c` varchar(10) DEFAULT NULL
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Query OK, 0 rows affected (0.02 sec) mysql> alter table t discard tablespace;
Query OK, 0 rows affected (0.02 sec)

三、拷贝ibd文件到对应路径,并import tablespace

[mysql@dbadb05 reco]$ ll
total 16
-rw-r----- 1 mysql mysql 67 Aug 6 15:46 db.opt
-rw-r----- 1 mysql mysql 8602 Aug 6 15:47 t.frm
[mysql@dbadb05 reco]$ cp /mysql/backup/reco/t.ibd .
[mysql@dbadb05 reco]$ ls -lrt
total 112
-rw-r----- 1 mysql mysql 67 Aug 6 15:46 db.opt
-rw-r----- 1 mysql mysql 8602 Aug 6 15:47 t.frm
-rw-r----- 1 mysql mysql 98304 Aug 6 15:49 t.ibd [mysql@dbadb05 reco]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.22-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use reco;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed, 1 warning
mysql> show warnings\G;
*************************** 1. row ***************************
Level: Warning
Code: 1287
Message: 'COM_FIELD_LIST' is deprecated and will be removed in a future release. Please use SHOW COLUMNS FROM statement instead
*************************** 2. row ***************************
Level: Warning
Code: 1814
Message: InnoDB: Tablespace has been discarded for table 't'
2 rows in set (0.00 sec) ERROR:
No query specified mysql> alter table t import tablespace;
Query OK, 0 rows affected, 1 warning (0.03 sec) mysql> show warnings\G;
*************************** 1. row ***************************
Level: Warning
Code: 1810
Message: InnoDB: IO Read error: (2, No such file or directory) Error opening './reco/t.cfg', will attempt to import without schema verification
1 row in set (0.00 sec) ERROR:
No query specified

四、查看表中的数据

mysql> select * from t;
+------+------+------+
| a | b | c |
+------+------+------+
| 1 | 1 | a |
+------+------+------+
1 row in set (0.00 sec)

五、没有mysqlfrm工具,恢复DDL的方法
仅供mysqlfrm工具时,尝试性恢复。
1、随意建立一个数据库和一张表

mysql> create database reco;
Query OK, 1 row affected (0.01 sec) mysql> use reco;
Database changed
mysql> create table t( c1 int);
Query OK, 0 rows affected (0.03 sec) mysql> show create table t\G;
*************************** 1. row ***************************
Table: t
Create Table: CREATE TABLE `t` (
`c1` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
1 row in set (0.00 sec) ERROR:
No query specified

2、拷贝需要恢复的frm文件到对应位置,并覆盖

mysql> system cp /mysql/backup/reco/t.frm /mysql/data/reco/t.frm
mysql> show create table t\G;
*************************** 1. row ***************************
Table: t
Create Table: CREATE TABLE `t` (
`c1` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
1 row in set (0.00 sec) ERROR:
No query specified mysql> flush table t;
Query OK, 0 rows affected (0.01 sec) mysql> show create table t\G;
ERROR 1146 (42S02): Table 'reco.t' doesn't exist
ERROR:
No query specified

3、此时报错,表报错,意料中的事情,查看mysql的错误日志
[Warning] InnoDB: Table reco/t contains user defined columns in InnoDB, but columns in MySQL. Please check INFORMATION_SCHEMA.INNODB_SYS_COLUMNS and http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue.

注意到日志中的信息,我们定义了1个列,但是MySQL中有3列。

4、删除原来的表,建立相同个数的列,名称和类型随意。

mysql> drop table t;
Query OK, 0 rows affected (0.02 sec) mysql> create table t(c1 int,c2 int, c3 int);
Query OK, 0 rows affected (0.02 sec) mysql> show create table t\G;
*************************** 1. row ***************************
Table: t
Create Table: CREATE TABLE `t` (
`c1` int(11) DEFAULT NULL,
`c2` int(11) DEFAULT NULL,
`c3` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
1 row in set (0.00 sec) ERROR:
No query specified

5、重复第二步,覆盖frm文件,就可以获得定义语句,结果与第一部分得出的一样

mysql> system cp /mysql/backup/reco/t.frm /mysql/data/reco/t.frm
mysql> show create table t\G;
*************************** 1. row ***************************
Table: t
Create Table: CREATE TABLE `t` (
`c1` int(11) DEFAULT NULL,
`c2` int(11) DEFAULT NULL,
`c3` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
1 row in set (0.00 sec) ERROR:
No query specified mysql> flush table t;
Query OK, 0 rows affected (0.01 sec) mysql> show create table t\G;
*************************** 1. row ***************************
Table: t
Create Table: CREATE TABLE `t` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
`c` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
1 row in set (0.01 sec) ERROR:
No query specified

六、安全性问题
MySQL的这个设计,方便了恢复。但是有着严重的安全隐患,一旦这两个文件被非法获取,所有数据将被泄露。

How To:利用frm和idb文件进行数据恢复.txt的更多相关文章

  1. 【转&参考】MySQL利用frm和ibd文件进行数据恢复

    MySQL利用frm和idb文件进行数据恢复 源MySQL现状: 版本:5.6.* 存储引擎:innodb存储引擎 要恢复数据库:skill 重点要恢复表:slot_value 已有的文件: 备份了所 ...

  2. MySQL 利用frm文件和ibd文件恢复表结构和表数据

    文章目录 frm文件和ibd文件简介 frm文件恢复表结构 ibd文件恢复表数据 通过脚本利用ibd文件恢复数据 通过shell脚本导出mysql所有库的所有表的表结构 frm文件和ibd文件简介 在 ...

  3. MYSQL数据库根据data文件中的.frm和ibd文件恢复单表数据

    数据库误操作,把表的字段删除了,关键是被删除的字段的数据很重要,现在想要恢复数据,下面说说是怎么操作的. 数据库只剩.frm和.ibd文件了,按照网上的做法分如下两步来进行:一.找回表结构,二.找回数 ...

  4. Linux 利用进程打开的文件描述符(/proc)恢复被误删文件

    Linux 利用进程打开的文件描述符(/proc)恢复被误删文件 在 windows 上删除文件时,如果文件还在使用中,会提示一个错误:但是在 linux 上删除文件时,无论文件是否在使用中,甚至是还 ...

  5. 利用Socket远程发送文件

    思想: 1.注意使用两个通道,一个普通对象通信通道,另一个纯净的文件字节流通道 2.利用通信通道发送文件请求,新建字节流通道,开始发送文件

  6. MySQL 通过idb文件恢复Innodb 数据【转】

    昨晚收到一则求助,一个用户的本地数据库的重要数据由于误操作被删除,需要进行紧急恢复,用户的数据库日常并没有进行过任何备份,binlog也没有开启,所以从备份和binlog入手已经成为不可能,咨询了丁奇 ...

  7. (Unity)Unity自定义Debug日志文件,利用VS生成Dll文件并使用Dotfuscated进展混淆,避免被反编译

    Unity自定义Debug日志文件,利用VS生成Dll文件并使用Dotfuscated进行混淆,避免被反编译. 1.打开VS,博主所用版本是Visual Studio 2013. 2.新建一个VC项目 ...

  8. 使用XML序列化器生成XML文件和利用pull解析XML文件

    首先,指定XML格式,我指定的XML格式如下: <?xml version='1.0' encoding='utf-8' standalone='yes' ?> <message&g ...

  9. 利用shell脚本统计文件中出现次数最多的IP

    比如有如下文件test.txt 1  134.102.173.43 2  134.102.173.43 3  134.102.171.42 4  134.102.170.9 要统计出现次数最多的IP可 ...

随机推荐

  1. Gerrit配置--用户配置

    环境: Gerrit Server:172.16.206.133 Client:172.16.206.129 1.在Gerrit服务器上创建用户 Gerrit服务器使用的是HTTP认证类型,并用htt ...

  2. WebDriverWait显示等待

    等待页面加载完成,找到某个条件发生后再继续执行后续代码,如果超过设置时间检测不到则抛出异常 WebDriverWait(driver, timeout, poll_frequency=0.5, ign ...

  3. _bzoj2049 [Sdoi2008]Cave 洞穴勘测【LCT】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2049 裸的LCT,保存LCT模版.说一下出bug的几个地方叭: ①,rotate时,没有判断 ...

  4. 洛谷 P1816 忠诚

    https://www.luogu.org/problemnew/show/1816 st表模板 #include<cstdio> #include<algorithm> us ...

  5. 判素数+找规律 BestCoder Round #51 (div.2) 1001 Zball in Tina Town

    题目传送门 /* 题意: 求(n-1)! mod n 数论:没啥意思,打个表能发现规律,但坑点是4时要特判! */ /***************************************** ...

  6. 解题报告:hdu 1073 Online Judge

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1073 Problem Description Ignatius is building an Onli ...

  7. C#模版学习研究

    原文链接1   原文链接2 using System; using System.Collections.Generic; using System.Text; using T = System.By ...

  8. Volley的初步了解

    Volley的介绍 Volley是什么? 2013年Google I/O大会上推出的网络请求和图片加载框架 其优点是api简单,性能优秀 非常适合数据量不大但是通信频繁的网络请求,而对于大数据量的操作 ...

  9. 017:COM1无法打开

    重新安装系统以后,COM1无法正常打开,重启以后也是如此.到设备管理器下,禁用COM1然后重启可以正常使用.修改COM1为别的COM号,重启以后可以正常使用.用Pcomm控件,打开该串口,错误号是-8 ...

  10. 【Hibernate】对应各种数据库的方言