有idata1文件的話好像更好恢復(fù)齿坷,以下步驟親自嘗試,屢試不爽初斑。數(shù)據(jù)無價(jià)辛润,請(qǐng)做好備份。
-
首先恢復(fù)表結(jié)構(gòu)
- 首先建立所有需要恢復(fù)數(shù)據(jù)的表见秤,相同的表名(內(nèi)部字段隨意)砂竖。
- 停止mysql服務(wù),將所有的frm文件替換掉當(dāng)前數(shù)據(jù)目錄文件中的frm鹃答,請(qǐng)注意備份當(dāng)前數(shù)據(jù)庫(kù)文件乎澄,避免失敗后數(shù)據(jù)庫(kù)無法正常使用。
- 文件授權(quán)测摔,下同:
chown -R mysql:mysql *.frm / chown -R mysql:mysql *.ibd
- 啟動(dòng)mysql服務(wù) 進(jìn)入mysql
-
開始恢復(fù)表數(shù)據(jù)
- 將全部的表discard tablespace 使用以下sql 此操作會(huì)刪除 idb文件置济,請(qǐng)注意備份
alter table table_name discard tablespace;
- 檢查看看還有沒有剩余的ibd文件,看下是否全部被自動(dòng)刪除锋八。
- 然后將舊的數(shù)據(jù)庫(kù) ibd文件 拷貝到當(dāng)前數(shù)據(jù)目錄文件中
- 文件授權(quán)
- 將全部的表 import tablespcae 使用sql
alter table table_name import tablespace;
以上幾個(gè)步驟會(huì)出錯(cuò)的幾個(gè)點(diǎn) 排查:
Schema mismatch (Table has ROW_TYPE_DYNAMIC row format, .ibd file has ROW_TYPE_COMPACT row format.)
- 該問題可見 mysql版本不同 表創(chuàng)建問題 重新創(chuàng)建一下表結(jié)構(gòu)
When trying to create a table with the same definition on 5.7, you’ll need to change it to:
CREATE TABLEfoo
(. . .) ENGINE=InnoDB ROW_FORMAT=compact
Tablespace is missing for table database name.table name.
- 查看table name.ibd 文件是否存在浙于,文件權(quán)限是否正確
Cannot delete or update a parent row: a foreign key constraint fails ()
- 刪除數(shù)據(jù)庫(kù)外鍵配置
此上 就完成了數(shù)據(jù)恢復(fù) 歡迎補(bǔ)充,僅表示:親測(cè)有效挟纱,接受吐槽羞酗。