MySQL 5.6.26 通過frm & ibd 恢複資料過程
在A伺服器上建立資料庫bkjia
root(yoon)> show create table bkjia\G
*************************** 1. row ***************************
Table: bkjia
Create Table: CREATE TABLE `bkjia` (
`id` int(11) DEFAULT NULL,
`name` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
插入資料
root(bkjia)> insert into bkjia values (1,'HANK');
Query OK, 1 row affected (1.01 sec)
root(bkjia)> insert into bkjia values (2,'bkjia');
Query OK, 1 row affected (0.04 sec)
root(bkjia)> insert into bkjia values (3,'GARY');
Query OK, 1 row affected (0.00 sec)
root(bkjia)> insert into bkjia values (4,'NIKO');
Query OK, 1 row affected (0.02 sec)
root(bkjia)> select * from bkjia;
+------+------+
| id | name |
+------+------+
| 1 | HANK |
| 2 | bkjia |
| 3 | GARY |
| 4 | NIKO |
+------+------+
4 rows in set (0.00 sec)
在B伺服器上,添加參數innodb_force_recovery=1並重啟,建立空資料庫bkjia,並建立表yoon
mysql> create database bkjia;
use yooQuery OK, 1 row affected (1.01 sec)
mysql> use bkjia;
Database changed
mysql> CREATE TABLE `bkjia` (
-> `id` int(11) DEFAULT NULL,
-> `name` varchar(20) DEFAULT NULL
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.09 sec)
將表結構和空間脫離
mysql> alter table bkjia discard tablespace;
Query OK, 0 rows affected (0.02 sec)
將A伺服器上的ibd資料檔案傳輸至B伺服器上
scp bkjia.ibd 182.19.4.7:/export/data/mysql/data/bkjia
修改許可權
chown -R mysql.mysql bkjia.ibd
將表結構和空間建立關係
mysql> alter table bkjia import tablespace;
Query OK, 0 rows affected, 1 warning (0.04 sec)
查詢資料
mysql> select * from bkjia;
+------+------+
| id | name |
+------+------+
| 1 | HANK |
| 2 | bkjia |
| 3 | GARY |
| 4 | NIKO |
+------+------+
4 rows in set (0.00 sec)
詳細步驟如下:
1、停止mysql服務,添加innodb_force_recovery=1 ,啟動mysql服務
2、建立新資料庫,建立相同表結構的表(表結構必須相同)
3、執行alter table tb discard tablespace;
4、刪除表的ibd檔案
5、跨伺服器複製表ibd檔案
6、修改ibd檔案許可權,執行alter table tb import tablespace;
本文永久更新連結地址: