MySQL MyISAM表结构的恢复方法是怎样的呢?这是很多人都提过的问题,下面就为您详细介绍MySQL MyISAM表结构的恢复方法,供您参考。
MySQL MyISAM类型的表恢复相对比较简单。
同样先假定需要恢复的表的FRM文件为test_myisam.frm,表结构为
mysql> create table test_myisam -> (A int(11) default NULL, -> B varchar(30) default NULL, -> C date default NULL) engine=myisam; Query OK, 0 rows affected (0.05 sec)
恢复过程如下:
1. 直接将test_myisam.frm拷贝到正常数据库对应的数据目录下。这时测试
mysql> show tables; +--------------+ | Tables_in_aa | +--------------+ | test_innodb | | test_myisam | +--------------+ 3 rows in set (0.00 sec) mysql> desc test_myisam; ERROR 1017 (HY000): Can't find file: 'test_myisam' (errno: 2)
发现只能通过show tables命令看见表名,但是表结构还是没有恢复,desc命令报错。
2. 在与test_myisam.frm同一目录建立以下2个文件,文件内容可以为空:
test_myisam.MYD test_myisam.MYI
3. 在MYSQL命令行使用MYSQL本身的数据表恢复命令repair命令恢复表,如下:
mysql> repair table test_myisam USE_FRM; +-----------------+--------+----------+----------+ | Table | Op | Msg_type | Msg_text | +-----------------+--------+----------+----------+ | aa.test_myisam | repair | status | OK | +-----------------+--------+----------+----------+ 1 row in set (0.00 sec)
根据结果可以知道,恢复命令执行成功,下边用desc命令测试下:
mysql> desc test_myisam; +-------+-------------+------+-----+---------+-------+ | 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.02 sec)
果然恢复成功了。