在另外一个机器上准备测试数据,并传输到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. #!/usr/bin/env ruby 与 #!/usr/bin/ruby 的区别(copy)

    [说明:资料来自http://blog.csdn.net/wh_19910525/article/details/8040494] 脚本语言的第一行,目的就是指出,你想要你的这个文件中的代码用什么可执 ...

  2. [知识积累]python3使用xlwt时写入文档字体颜色和边框样式

    可借鉴的网址:https://www.programcreek.com/python/example/39979/xlwt.Alignment 可以直接通过pip安装xlwt 个人理解: xlwt中对 ...

  3. 转载别人的ognl

    一.循环遍历集合 1.在jsp中引入标准函数声明<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix=" ...

  4. 洛谷P4331 [BOI2004]Sequence 数字序列(左偏树)

    传送门 感觉……不是很看得懂题解在说什么? 我们先把原数列$a_i-=i$,那么本来要求递增序列,现在只需要求一个非严格递增的就行了(可以看做最后每个$b_i+=i$,那么非严格递增会变为递增) 如果 ...

  5. bind: Invalid argument

    出现此问题在于,listen函数在socket函数和bind函数之间. 例: /*客户端程序开始建立sockfd描述符*/ listenfd = socket(AF_INET,SOCK_STREAM, ...

  6. HDU 5558 后缀数组

    思路: 这是一个错误的思路, 因为数据水才过= = 首先求出来后缀数组 把rank插到set里 每回差i两边离i近的rank值,更新 如果LCP相同,暴力左(右)继续更新sa的最小值 //By Sir ...

  7. _bzoj2818 Gcd【线性筛法 欧拉函数】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2818 若gcd(x, y) = 1,则gcd(x * n, y * n) = n.那么,当y ...

  8. Sqlite数据库中索引的使用、索引的优缺点[转]

    原文链接1   原文链接2 3. 索引的种类 1)聚集索引:表中行的物理顺序与键值的逻辑(索引)顺序相同.因为数据的物理顺序只能有一种,所以一张表只能有一个聚集索引.如果一张表没有聚集索引,那么这张表 ...

  9. NSSet转成NSArray 以及NSSortDescriptor的使用

    //如果想排序以后再取,可以这样:NSSet *users = [groupUser users]; //如果是存的字典,则key后面写的是想按照哪个关键字进行排序 NSSortDescriptor ...

  10. 【图片匹配】--- SIFT_Opencv3.1.0_C++_ubuntu

    最近在捣鼓图片相似性匹配算法.这里先说一点必要的题外话: 如果是在同一个object不同角度拍摄的多张图片中,使用SIFT可以有不错的效果: 如果是寻找类别相同的图片(可能不是同一object),SI ...