在另外一个机器上准备测试数据,并传输到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. hdu3555(数位DP dfs/递推)

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submi ...

  2. 使用jQuery的tab控件

    以前写winform程序的时候tab控件是非常容易使用的,写网页时确费了我不少劲,主要原因是jQuery的混乱. 有很多前端控件都提供tab,像bootstrap等,这里只说jQuery的. 下载相应 ...

  3. Pow(x, n) 位运算总结 典型

    https://leetcode.com/problems/powx-n/ Implement pow(x, n), which calculates x raised to the power n  ...

  4. Gym 100531A Alarm Clock (水题)

    题意:给定一个被高亮的数,问你是不是有个时间恰好高亮是这个数. 析:直接暴力,直接暴力,枚举每一位时间,当然也可以枚举时间,能找到就是有,找不到就算了. 代码如下: #pragma comment(l ...

  5. linux下tab键在命令行情况下的强大

    tab自动补全命令,包括可以补全比较长的文件名,速度快的不是一点点

  6. JS开发备忘笔记-- Javascript中document.execCommand()的用法

    document.execCommand()方法处理Html数据时常用语法格式如下:document.execCommand(sCommand[,交互方式, 动态参数]) 其中:sCommand为指令 ...

  7. 【Maven】CentOS7使用Nexus3搭建maven私服

    一.简介 Maven是一个采用纯Java编写的开源项目管理工具, Maven采用了一种被称之为Project Object Model(POM)概念来管理项目,所有的项目配置信息都被定义在一个叫做PO ...

  8. the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf

    一:开始Nginx的SSL模块 1.1 Nginx如果未开启SSL模块,配置Https时提示错误 原因也很简单,nginx缺少http_ssl_module模块,编译安装的时候带上--with-htt ...

  9. Jumping Jack CodeForces - 11B

    Jumping Jack CodeForces - 11B 就是一个贪心. 基本思路: 正负没有关系,先取绝对值. 首先跳过头,然后考虑怎么回来. 设超过头的步数为kk.如果kk为偶数,那么直接在前面 ...

  10. Java中的流(4)InputStream,InputStreamReader,BufferedReader关系

    InputStream是字节流,InputStreamReader将字节流转成字符流,BufferedReader将字符流转成字符缓冲,开始读字符. 1.InputStream.OutputStrea ...