数据文件物理误删除frm文件处理方法 需要注意的是MySQL 8.0的新特性中弃用了将表定义元数据文件.frm存储在文件系统上(8.0开始存放在数据字典表),原因是易受文件系统相关错误的影响(例如被误删除)、减少文件扫描的性能消耗等。所以本例误删除frm文件场景将用MySQL 5.7来演示。 排查方法 表的.frm文件被删除后,数据库将看不到该表,表也无法被操作 mysql> create table scott_tab(name varchar(200)); mysql> insert into scott_tab SELECT CONCAT(table_schema,'_',table_name) FROM information_schema.TABLES; # rm -f scott_tab.frm # 数据库中无法被show查看 mysql> show tables like 'scott_tab'G Empty set (0.01 sec) # 相关操作也无法被执行 mysql> select * from scott_tab ; ERROR 1146 (42S02): Table 'sbtest.scott_tab' doesn't exist mysql> delete from scott_tab ; ERROR 1146 (42S02): Table 'sbtest.scott_tab' doesn't exist 表.frm文件被删除后有两种方式进行修复: 方法1,知道表结构情况下,在其它实例或测试库新建表后拷贝frm文件到故障实例 方法2,忘记表结构情况下,需要利用备份文件还原到测试库然后再拷贝frm到故障实例 方法1大致步骤如下 ## 测试库中新建原样的表 mysql> create table scott_tab(name varchar(20)); ## 文件系统层拷贝测试库中建好的表结构到指定目录,注意 scott_tab.frm 所属的用户如果不是MySQL,需要改正过来 # ls scott_tab* scott_tab.ibd # cp ../test/scott_tab.frm . # ls scott_tab* scott_tab.frm scott_tab.ibd ## 数据库中验证 mysql> use sbtest; mysql> show tables like 'scott_tab'G mysql> select * from scott_tab G 方法2 大致步骤如下: ## 以存在逻辑备份文件为例,将数据恢复到测试实例 # mysql -P3307 -uroot -proot < all_db_with_data.sql ## 然后再将测试实例中恢复完成的frm文件拷贝到故障实例相应目录 (操作步骤与方法1中类似,不做赘述)