- 論壇徽章:
- 8
|
本帖最后由 我忒忙 于 2016-05-12 11:39 編輯
MyISAM表的.frm文件丟失后的恢復(fù)方法:
1、創(chuàng)建實(shí)驗(yàn)用的MyISAM表t1,并插入數(shù)據(jù):
mysql> create table t1(id int) engine=myisam;
Query OK, 0 rows affected (0.01 sec)
mysql> insert into t1 values(1),(2),(3),(4),(5),(6),(7),( ;
Query OK, 8 rows affected (0.00 sec)
Records: 8 Duplicates: 0 Warnings: 0
2、刪除t1表的.frm文件
[root@localhost gusha]# cd /var/lib/mysql/gusha
[root@localhost gusha]# ls
db.opt t1.MYI t1.frm t1.MYD
[root@localhost gusha]# rm -rf t1.frm
此時在gusha庫里已經(jīng)查詢不到t1表了:
mysql> show tables;
Empty set (0.00 sec)
還能查詢t1表里的內(nèi)容是因?yàn)橛芯彺,清下緩存?br />
mysql> select * from t1;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
+------+
8 rows in set (0.00 sec)
mysql> flush tables;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from t1;
ERROR 1146 (42S02): Table 'gusha.t1' doesn't exist
3、進(jìn)行恢復(fù),把gusha庫對應(yīng)的文件夾里的t1.MYD和t1.MYI文件移動到其它文件夾:
[root@localhost gusha]# mv t1.MY* /var/lib/backup/
[root@localhost gusha]# ls
db.opt
在gusha庫里重新創(chuàng)建一個t1表,表結(jié)構(gòu)和原來的t1表一樣:
mysql> create table t1(id int) engine=myisam;
Query OK, 0 rows affected (0.00 sec)
把t1.MYD和t1.MYI文件移動會gusha庫對應(yīng)的文件夾:
[root@localhost gusha]# mv /var/lib/backup/t1.MY* .
mv: overwrite `./t1.MYD'? y
mv: overwrite `./t1.MYI'? y
此時MySQL會自動修復(fù)t1表
mysql> select * from t1;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
+------+
8 rows in set (0.00 sec)
如果沒有自動修復(fù),則執(zhí)行下面命令進(jìn)行修復(fù):
mysql> repair table t1;
+----------+--------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+----------+--------+----------+----------+
| gusha.t1 | repair | status | OK |
+----------+--------+----------+----------+
1 row in set (0.00 sec)
到此MyISAM表t1.frm丟失后又恢復(fù)回來了
更多精彩MySQL內(nèi)容 前關(guān)注我:
QQ截圖20160417100740.png (12.72 KB, 下載次數(shù): 48)
下載附件
2016-05-12 11:39 上傳
|
|