• ADADADADAD

    MyISAM表的.frm文件丢失后怎么恢复[ mysql数据库 ]

    mysql数据库 时间:2024-11-26 22:17:09

    作者:文/会员上传

    简介:

    MyISAM表的.frm文件丢失后的恢复方法:1、创建实验用的MyISAM表t1,并插入数据:mysql> create table t1(id int) engine=myisam;Query OK, 0 rows affected (0.01 sec)mysql> ins

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。

    MyISAM表的.frm文件丢失后的恢复方法:

    1、创建实验用的MyISAM表t1,并插入数据:

    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),(8);

    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.MYIt1.frm t1.MYD

    [root@localhost gusha]# rm -rf t1.frm

    此时在gusha库里已经查询不到t1表了:

    mysql> show tables;

    Empty set (0.00 sec)

    还能查询t1表里的内容是因为有缓存,清下缓存:

    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、进行恢复,把gusha库对应的文件夹里的t1.MYD和t1.MYI文件移动到其它文件夹:

    [root@localhost gusha]# mv t1.MY* /var/lib/backup/

    [root@localhost gusha]# ls

    db.opt

    在gusha库里重新创建一个t1表,表结构和原来的t1表一样:

    mysql> create table t1(id int) engine=myisam;

    Query OK, 0 rows affected (0.00 sec)

    把t1.MYD和t1.MYI文件移动会gusha库对应的文件夹:

    [root@localhost gusha]# mv /var/lib/backup/t1.MY* .

    mv: overwrite `./t1.MYD'? y

    mv: overwrite `./t1.MYI'? y

    此时MySQL会自动修复t1表

    mysql> select * from t1;

    +------+

    | id|

    +------+

    |1 |

    |2 |

    |3 |

    |4 |

    |5 |

    |6 |

    |7 |

    |8 |

    +------+

    8 rows in set (0.00 sec)

    如果没有自动修复,则执行下面命令进行修复:

    mysql> repair table t1;

    +----------+--------+----------+----------+

    | Table| Op | Msg_type | Msg_text |

    +----------+--------+----------+----------+

    | gusha.t1 | repair | status| OK|

    +----------+--------+----------+----------+

    1 row in set (0.00 sec)

    MyISAM表的.frm文件丢失后怎么恢复.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载
    热门标签: myisam