在另外一个机器上准备测试数据,并传输到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. Java:目录

    ylbtech-Java:目录 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http://ylbtech. ...

  2. React VSCode插件

    可以安装2个插件,一个是 Atuo Rename Tag 一个 Auto Close Tag 这样就好都了

  3. CodeForces 723D Lakes in Berland (dfs搜索)

    题意:给定一个n*m的矩阵,*表示陆地, . 表示水,一些连通的水且不在边界表示湖,让你填最少的陆地使得图中湖剩下恰好为k. 析:很简单的一个搜索题,搜两次,第一次把每个湖的位置和连通块的数量记下来, ...

  4. idea打印gc日志

    1.在idea里添加配置 -XX:+PrintGCDetails 2.打印GC的详细信息: -XX:+PrintGCDetails 解释:打印GC详细信息. -XX:+PrintGCTimeStamp ...

  5. [转]Boosting

    1 Boosting算法的起源 Boosting方法是一种用来提高弱分类算法准确度的方法,这种方法通过构造一个预测函数系列,然后以一定的方式将他们组合成一个预测函数.Boosting是一种提高任意给定 ...

  6. [SDOI2013]spring

    Description Input Output Sample Input 3 3 1 2 3 4 5 6 1 2 3 0 0 0 0 0 0 4 5 6 Sample Output 2 HINT 容 ...

  7. PHP获取今天内的时间 今天开始和结束的时间戳

    $t = time(); $start = mktime(0,0,0,date("m",$t),date("d",$t),date("Y", ...

  8. Android偏好设置(1)概述和Preferences简介

    1.Overview Instead of using View objects to build the user interface, settings are built using vario ...

  9. Visual studio docker build no such file or directory

    在我构建新的镜像的时候, 发生 了  no such file or directory 的错误.  这个错误找了半天, 没头绪,项目结构是这样的: WebApplication1 建立在根目录下,是 ...

  10. 转 oracle apex 使用

    https://wenku.baidu.com/view/e5a4226955270722182ef725.html