08月09, 2021
收藏本站

innodb表空间.ibd文件被误删除

声明:本文从爱可生博客(数据库表空间被 rm 后,怎么处理)中了解到,不属于原创。

问题现象:

  1. innodb表的.ibd文件被删除
  2. 执行DML不会报错,而DDL却会报错如下:
    [ERROR] InnoDB: Cannot rename './test/t_school_auth.ibd' to './test/#sql-ib34523-911103856.ibd' for space ID 31366 because the source file does not exist.

处理:

  1. 不要重启mysql
  2. lsof | grep t_school_auth.ibd
    [root@k8s-worker tmp]# lsof |grep t_school_auth
    mysqld      2093                mysql   97uW     REG                8,3    163840   1
    mysqld      2093  2134          mysql   97uW     REG                8,3    163840   1
    mysqld      2093  2135          mysql   97uW     REG                8,3    163840   1
    mysqld      2093  2136          mysql   97uW     REG                8,3    163840   1
    mysqld      2093  2137          mysql   97uW     REG                8,3    163840   1
    mysqld      2093  2138          mysql   97uW     REG                8,3    163840   1
    mysqld      2093  2139          mysql   97uW     REG                8,3    163840   1
    mysqld      2093  2140          mysql   97uW     REG                8,3    163840   1
    mysqld      2093  2141          mysql   97uW     REG                8,3    163840   
  3. ls -l /proc/2093/fd/97
    其中2093为上面第2列,97位第5列前缀数字
    [root@k8s-worker tmp]# ls -l /proc/2093/fd/97 
    lrwx------ 1 mysql mysql 64 Aug  9 09:25 /proc/2093/fd/97 -> /var/lib/mysql/test/t_school_auth.ibd (deleted)
  4. cp /proc/2093/fd/97 /var/lib/mysql/test/t_school_auth.ibd
  5. chown mysql:mysql /var/lib/mysql/test/t_school_auth.ibd
  6. 重启mysql

Comments