• 数据文件物理误删除ibd文件处理方法


    数据文件物理误删除ibd文件处理方法
    
     
    在MySQL数据库中表的ibd即表空间文件被误删除影响比较大,虽然删除后可以正常读写表数据,但是在重启后表的任何访问动作都将报错:
    ## 删除表空间后,表仍然可以读写
    
    # rm scott_tab.ibd -f
    
    mysql> insert into  scott_tab values ( 'test');
    Query OK, 1 row affected (0.00 sec)
    
    mysql> select * from scott_tab where name='test';
    +------+
    | name |
    +------+
    | test |
    +------+
    
    1 row in set (0.00 sec)
    
    ## 重启后,任何访问表操作都将报错
    mysql> select * from scott_tab where name='test';
    ERROR 1812 (HY000): Tablespace is missing for table `scott`.`scott_tab`.
    mysql> insert into  scott_tab values ( 'test2');
    ERROR 1812 (HY000): Tablespace is missing for table `scott`.`scott_tab`.
    
    
    解决方法
    对于.ibd文件误删除后最为快速的修复方式是通过全备份、表空间导入、回放binlog的方式进行组合还原,具体操作步骤如下
    
    ## 通过全备份文件(本例是逻辑全备)还原到临时或测试实例
    mysql -P3307 -uroot -proot < all_db_with_data.sql
    
    ## 回放binlog(注意从全备文件找到起始位置、并只过滤 scott 库节省时间)
    mysqlbinlog -vvv mysql-bin.000007 --start-position=604 --database=scott |mysql -uroot -proot -P3307
    
    ## 故障实例丢弃表空间(稳妥操作,虽然表空间已被误删除)
    
    mysql>  alter table scott_tab discard tablespace;
    Query OK, 0 rows affected, 2 warnings (0.01 sec)
    
    mysql>  show warningsG
    *************************** 1. row ***************************
      Level: Warning
       Code: 1812
    Message: InnoDB: Tablespace is missing for table scott/scott_tab.
    *************************** 2. row ***************************
      Level: Warning
       Code: 1812
    Message: InnoDB: Tablespace is missing for table scott/scott_tab.
    2 rows in set (0.00 sec)
    
    ## 临时实例导出备份表的表空间
    mysql> flush table scott_tab for export;
    Query OK, 0 rows affected (0.00 sec)
    
    ## 拷贝临时实例的ibd表空间到故障实例指定数据目录下
    cp /data/mysql_3307/test/scott_tab.ibd ./
    
    ## 不要忘记最后解锁临时实例对应表scott_tab
    mysql> unlock tables;
    Query OK, 0 rows affected (0.00 sec)
    
    ## 故障实例导入表空间
    mysql> alter table scott_tab import tablespace;
    Query OK, 0 rows affected, 1 warning (0.21 sec)
    
    ## 验证表是否读写正常
    mysql> select * from scott_tab ;
     
  • 相关阅读:
    [转]Connecting To SQLite Database Using Node.js
    [转]Ubuntu安装ss客户端
    ubuntu18.04连接pptpd服务器(未成功)
    ubuntu18.04安装DB2 11.1 Express-c
    ubuntu 18.04使用sysbench测试MySQL性能
    ubuntu18.04手动安装二进制MySQL8.0
    ubuntu 18.04下载mysql8.0.13源码并编译安装(暂时没有成功)
    Linux使用sleep进行延迟实验
    『浅入浅出』MySQL 和 InnoDB
    『浅入深出』MySQL 中事务的实现
  • 原文地址:https://www.cnblogs.com/l10n/p/13502988.html
Copyright © 2020-2023  润新知