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


    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.MYI    t1.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表t1.frm丢失后又恢复回来了
     
    更多MySQL精彩内容 请关注我:
  • 相关阅读:
    请教visiouml活动图中动作状态和状态的区别谢谢 软件工程管理 软件规划版
    !!!IT人员迅速提升自我效率的十大方法
    如何在Visio的UML活动图中(判断及控制流)添加文字啊????
    Convert Standard String to System::String
    m_pRecordset遍历记录集之后,m_pRecordsetMoveFirst()为什么会出错
    !!! C++/CLI中使用using namespace System::Windows::Forms;+MessageBox报错最重要的是看MSDN 每个函数的使用例子
    !!!创建 UML 活动图 Visio Office_com
    C#反射之AssemblyCLR/c++可以通过反射调用c#类库
    请允许我进入你的世界
    以赛庆党日
  • 原文地址:https://www.cnblogs.com/da605839633/p/5477898.html
Copyright © 2020-2023  润新知