Home  >  Article  >  Database  >  恢复MySQL InnoDB表结构的方法

恢复MySQL InnoDB表结构的方法

WBOY
WBOYOriginal
2016-06-07 17:58:07849browse

MySQL InnoDB表结构的恢复方法是怎样的呢?下面就为您详细介绍MySQL InnoDB表结构的恢复步骤,如果您对此方面感兴趣的话,不妨一看。 MySQL InnoDB表结构的恢复: 假定:MYSQL数据库已经崩溃,目前只有对应表的frm文件,大家都知道,frm文件无法通过文本编辑

MySQL InnoDB表结构的恢复方法是怎样的呢?下面就为您详细介绍MySQL InnoDB表结构的恢复步骤,如果您对此方面感兴趣的话,不妨一看。

MySQL InnoDB表结构的恢复:

假定:MYSQL数据库已经崩溃,目前只有对应表的frm文件,大家都知道,frm文件无法通过文本编辑器查看,因为如果不恢复,基本上来说对我们没什么用。这里我们为了测试,假定该文件为test_innodb.frm.

该表创建脚本如下:

mysql> create table test_innodb 

    -> (A int(11) default NULL, 
    -> B varchar(30) default NULL, 
    -> C date default NULL) engine=innodb; 
Query OK, 0 rows affected (0.05 sec) 

恢复方法介绍(过程):

1. 在新的正常工作的MYSQL环境下建立一个数据库,比如aa.

2. 在aa数据库下建立同名的数据表test_innodb,表结构随意,这里只有一个id字段,操作过程片段如下:

mysql> create table test_innodb (id bigint not null)engine=InnoDB; 
Query OK, 0 rows affected (0.09 sec) 

mysql> show tables; 
+--------------+ 
| Tables_in_aa | 
+--------------+ 
| test_innodb | 
+--------------+ 
2 rows in set (0.00 sec) 

mysql> desc test_innodb; 
+-------+------------+------+-----+---------+-------+ 
| Field | Type       | Null | Key | Default | Extra | 
+-------+------------+------+-----+---------+-------+ 
| id    | bigint(20) | NO   |     | NULL    |       | 
+-------+------------+------+-----+---------+-------+ 
1 row in set (0.00 sec) 

3.停止mysql服务器,将系统崩溃后留下的test_innodb.frm文件拷贝到新的正常数据库的数据目录aa下,覆盖掉下边同名的frm文件:

4.重新启动MYSQL服务。

5.测试下是否恢复成功,进入aa数据库,用desc命令测试下:

mysql> desc test_innodb; 
+-------+-------------+------+-----+---------+-------+ 
| Field | Type        | Null | Key | Default | Extra | 
+-------+-------------+------+-----+---------+-------+ 
| A     | int(11)     | YES |     | NULL    |       | 
| B     | varchar(30) | YES |     | NULL    |       | 
| C     | date        | YES |     | NULL    |       | 
+-------+-------------+------+-----+---------+-------+ 
3 rows in set (0.01 sec) 

OK,发现表结构已经恢复过来了。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn