某客户同时发起两个线程对表新增字段,被异常取消,导致表结构崩溃
mysql> select count(*) from table_a;
ERROR 1146 (42S02): Table 'database1.table_a' doesn't exist
bash
cd $data_dir/db_name/
ll table_a.*
table_a.frm ## 存表结构
table_a.ibd ## 存表数据
1.删除表元数据信息
bash
## 备份并挪走 frm 与 ibd 文件
## 使用历史表结构 建一张 新表
create table table_a(id int);
## 若新表建不成功,则是由于旧表的元数据信息仍然保留在数据库里
## 尝试 rename 旧表
alter table table_a rename to table_a_bak;
drop table table_a;
## 检查数据字典是否还存在该表信息
## 确认 InnoDB 字典里到底有没有这个表的 space ID
SELECT * FROM information_schema.innodb_sys_tables
WHERE name LIKE 'database1/table_a%';
## 查看表空间文件状态
SELECT * FROM information_schema.innodb_sys_tablespaces
WHERE name like 'database1/table_a%'
2.用正确的表结构新建表
bash
create table table_a(id int);
3.将新表的tablespace下线
bash
ALTER TABLE database1.table_a DISCARD TABLESPACE;
4.将旧表的 ibd 文件复制到 $data_dir/db_name/ 路径代替新表的数据,并正确赋权该文件
5.注册该表的数据
bash
ALTER TABLE database1.table_a IMPORT TABLESPACE;
SELECT count(*) FROM database1.table_a;