在A
服務(wù)器上創(chuàng)建數(shù)據(jù)庫(kù)yoon
root(yoon)> show create table yoon\G
*************************** 1. row ***************************
Table: yoon
Create Table: CREATE TABLE `yoon` (
`id` int(11) DEFAULT NULL,
`name` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
插入數(shù)據(jù)
root(yoon)> insert into yoon values (1,'HANK');
Query OK, 1 row affected (1.01 sec)
root(yoon)> insert into yoon values (2,'YOON');
Query OK, 1 row affected (0.04 sec)
root(yoon)> insert into yoon values (3,'GARY');
Query OK, 1 row affected (0.00 sec)
root(yoon)> insert into yoon values (4,'NIKO');
Query OK, 1 row affected (0.02 sec)
root(yoon)> select * from yoon;
+------+------+
| id | name |
+------+------+
| 1 | HANK |
| 2 | YOON |
| 3 | GARY |
| 4 | NIKO |
+------+------+
4 rows in set (0.00 sec)
在B服務(wù)器上,添加參數(shù)innodb_force_recovery=1并重啟,創(chuàng)建空數(shù)據(jù)庫(kù)yoon,并創(chuàng)建表yoon
MySQL> create database yoon;
use yooQuery OK, 1 row affected (1.01 sec)
mysql> use yoon;
Database changed
mysql> CREATE TABLE `yoon` (
-> `id` int(11) DEFAULT NULL,
-> `name` varchar(20) DEFAULT NULL
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.09 sec)
將表結(jié)構(gòu)和空間脫離
mysql> alter table yoon discard tablespace;
Query OK, 0 rows affected (0.02 sec)
將A服務(wù)器上的ibd數(shù)據(jù)文件傳輸至B服務(wù)器上
scp yoon.ibd 182.19.4.7:/export/data/mysql/data/yoon
修改權(quán)限
chown -R mysql.mysql yoon.ibd
將表結(jié)構(gòu)和空間建立關(guān)系
mysql> alter table yoon import tablespace;
Query OK, 0 rows affected, 1 warning (0.04 sec)
查詢數(shù)據(jù)
mysql> select * from yoon;
+------+------+
| id | name |
+------+------+
| 1 | HANK |
| 2 | YOON |
| 3 | GARY |
| 4 | NIKO |
+------+------+
4 rows in set (0.00 sec)
詳細(xì)步驟如下:
1、停止mysql服務(wù),添加innodb_force_recovery=1 ,啟動(dòng)mysql服務(wù)
2、創(chuàng)建新數(shù)據(jù)庫(kù),創(chuàng)建相同表結(jié)構(gòu)的表(表結(jié)構(gòu)必須相同)
3、執(zhí)行alter table tb discard tablespace;
4、刪除表的ibd文件
5、跨服務(wù)器復(fù)制表ibd文件
6、修改ibd文件權(quán)限,執(zhí)行alter table tb import tablespace;
文章標(biāo)題:MySQL5.6.26通過frm&ibd恢復(fù)數(shù)據(jù)過程
文章分享:
http://weahome.cn/article/pgcdhc.html