how to recovery innodb from Pages from .idb (Part III)
时间:2010-08-22 来源:Steven1981
----------------------------------------------
TEST STEP 0:创建测试环境:
----------------------
MYSQL 5140 at RHEL 5u4 X86_64
use test;
create table recover1 (id int auto_increment , c1 varchar(50), c2 varchar(100) ,primary key (id) ) engine=innodb;
insert into recover1(c1,c2) values ('aaaaaa','bbbbbb');
insert into recover1(c1,c2) select c1,c2 from recover1 ;
insert into recover1(c1,c2) select c1,c2 from recover1 ;
insert into recover1(c1,c2) select c1,c2 from recover1 ;
insert into recover1(c1,c2) select c1,c2 from recover1 ;
insert into recover1(c1,c2) select c1,c2 from recover1 ;
insert into recover1(c1,c2) select c1,c2 from recover1 ;
insert into recover1(c1,c2) select c1,c2 from recover1 ;
insert into recover1(c1,c2) select c1,c2 from recover1 ;
insert into recover1(c1,c2) select c1,c2 from recover1 ;
insert into recover1(c1,c2) select c1,c2 from recover1 ;
insert into recover1(c1,c2) select c1,c2 from recover1 ;
insert into recover1(c1,c2) select c1,c2 from recover1 ;
SQL> select count(*) from recover1;
+----------+
| count(*) |
+----------+
| 4096 |
+----------+
1 row in set (0.03 sec)
SQL> show create table recover1 G
*************************** 1. row ***************************
Table: recover1
Create Table: CREATE TABLE `recover1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`c1` varchar(50) DEFAULT NULL,
`c2` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16359 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
SQL> truncate table recover1 ;
Query OK, 0 rows affected (0.03 sec)
##注意,在这里,你需要在文件被重新覆盖前,对数据所在表空间做一个镜像。否则你的数据也就无法恢复了。 你可以对MYSQL做一个FAST_SHUTDOWN。
如果你使用了:innodb_file_per_table,那么数据表空间文件就是: .ibd.
如果你使用了共享表空间,那么就是ibdata1....
cp /home/mysql/data/mysql/test/recover1.ibd /opt
TEST STEP1:下载工具编码,并解压到指定目录,
----------------------
cd /opt
wget http://launchpad.net/percona-innodb-recovery-tool/trunk/release-0.4/+download/percona-innodb-recovery-tool.tar.gz
tar xzvf percona-innodb-recovery-tool.tar.gz
cd /opt/percona-innodb-recovery-tool/mysql-source
./configure
#注意这里不要MAKE。
TEST STEP2: 找出该表主键的“index_id”,
----------------------
mysql> CREATE TABLE `innodb_table_monitor` (`id` int(11) default NULL) ENGINE=InnoDB;
Query OK, 0 rows affected (0.01 sec)
[root@localhost mysql]# tail -20 /home/mysql/data/mysql/master-error.log
... ...
--------------------------------------
TABLE: name test/recover1, id 0 242, columns 6, indexes 1, appr.rows 0
COLUMNS: id: DATA_INT DATA_BINARY_TYPE DATA_NOT_NULL len 4; c1: type 12 len 150; c2: type 12 len 300; DB_ROW_ID: DATA_SYS prtype 256 len 6; DB_TRX_ID: DATA_SYS prtype 257 len 6; DB_ROLL_PTR: DATA_SYS prtype 258 len 7;
INDEX: name PRIMARY, id 0 447, fields 1/5, uniq 1, type 3
root page 3, appr.key vals 0, leaf pages 1, size pages 1
FIELDS: id DB_TRX_ID DB_ROLL_PTR c1 c2
#这里我们可以看到: INDEX: name PRIMARY, id 0 447 。
这个INDEX_ID我们下面会有用。
待续... ...