frm和ibd文件數據庫恢復----惜分飛


聯系:手機/微信(+86 17813235971) QQ(107644445)QQ咨詢惜分飛

標題:frm和ibd文件數據庫恢復

作者:惜分飛©版權所有[未經本人同意,不得以任何形式轉載,否則有進一步追究法律責任的權利.]

這次客戶rm -rf /var/lib/mysql刪除文件,刪除一半及時終止,但是已經有很多mysql相關文件被刪除,重要的ibdata文件已經被刪除,並且客戶嘗試了大量的恢復工作,對該分區進行了大量的寫入操作,導致后面通過對xfs文件系統進行分析,確認無法恢復對應的ibdata文件.比較幸運客戶需要的核心的mysql庫都還在(frm和ibd文件還存在)
20211224105004


對於這種情況,可以參考以前類似的處理方法:[MySQL異常恢復]mysql ibd文件恢復
由於客戶無法提供創建表語句需要通過對frm進行解析獲取語句,利用mysqlfrm獲取表創建語句

 

E:\3>mysqlfrm --server=root:oracle@192.168.222.79:3306 --diagnostic T_XIFENFEI.frm
WARNING: Using a password on the command line interface can be insecure.
# Source on 192.168.222.79: ... connected.
# CAUTION: The diagnostic mode is a best-effort parse of the .frm file. As such, it may not identify all of
   the components of the table correctly. This is especially true for damaged files.
   It will also not read the default values for the columns and the resulting statement may not be syntactically correct.
# Reading .frm file for EVALUATOR_T.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement:
 
CREATE TABLE `T_XIFENFEI` (
   `ID` varchar(32) COLLATE `utf8_general_ci` DEFAULT NULL comment '主鍵' ,
   `BO_TYPE_DEFINE_ID` varchar(32) COLLATE `utf8_general_ci` DEFAULT NULL comment '業務對象類型ID' ,
   `MAIN_ID` varchar(32) COLLATE `utf8_general_ci` DEFAULT NULL comment '業務對象主表記錄ID' ,
   `PARENT_ID` varchar(32) COLLATE `utf8_general_ci` DEFAULT NULL comment '父ID' ,
   `ROW_NUM` decimal(32,0) DEFAULT NULL comment '行號' ,
   `VERSION` decimal(32,6) DEFAULT NULL comment '版本' ,
   `CREATE_DATE` datetime DEFAULT NULL comment '創建時間' ,
   `UPDATE_DATE` datetime DEFAULT NULL comment '更新時間' ,
   `BO_SOURCE_ROW_ID` varchar(32) COLLATE `utf8_general_ci` DEFAULT NULL comment '來源明細行ID' ,
   `EVALUATORS` text COLLATE `utf8_general_ci` DEFAULT NULL,
   `IMPORTANCE` decimal(32,6) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8, COMMENT '評分人' ;
#...done.

對於有些獲取語句失敗,比如類似這樣錯誤

E:\TEMP\10000246_1108\db\ync2_fssc_2000003>mysqlfrm --server=root:oracle@192.168.222.79:3306 --diagnostic T_XFF.frm
Traceback (most recent call last):
   File "G:\ade\build\Python-2.7.6-windows-x86-64bit\lib\site-packages\cx_Freeze\initscripts\Console.py" ,
     line 27, in <module>
   File "scripts\mysqlfrm.py" , line 419, in <module>
   File ".\mysql\utilities\command\read_frm.py" , line 396, in read_frm_files_diagnostic
   File ".\mysql\utilities\common\frm_reader.py" , line 1538, in show_create_table_statement
   File ".\mysql\utilities\common\frm_reader.py" , line 1385, in _build_create_statement
   File ".\mysql\utilities\common\frm_reader.py" , line 1273, in _get_key_columns
IndexError: list index out of range

使用專門的工具對其進行解析
20211224105004


然后利用這些創建表語句在庫中創建表,並利用以下方法進行操作

 

mysql> alter table  `t_xifenfei` discard tablespace;       
Query OK, 0 rows affected (0.00 sec)
 
--上傳老的t_xifenfei.ibd文件,並修改所有者和屬組
 
mysql> alter table  `t_xifenfei` import tablespace;               
Query OK, 0 rows affected, 2 warnings (0.01 sec)
 
mysql> select count(1) from   `t_xifenfei` ;             
+----------+
| count(1) |
+----------+
|       78 |
+----------+
1 row in set (0.00 sec)

使用類似的方法對於數據進行批量處理,然后使用mysqldump進行導出.在這個ibd的discard和import的過程中,有些異常情況這三種錯誤的處理

mysql> alter table T_LOG_XIFENFEI                   import tablespace;
ERROR 1808 (HY000): Schema mismatch (Table has ROW_TYPE_DYNAMIC row format , .ibd file has ROW_TYPE_COMPACT row format .)
mysql> alter table     `T_LOG_XIFENFEI` import tablespace;
ERROR 1817 (HY000): Index corrupt: Externally stored column(4) has a reference length of 4 in the cluster index PRIMARY
mysql> alter table       `T_LOG_XIFENFEI` import tablespace;
ERROR 1815 (HY000): Internal error: Cannot reset LSNs in table `XFF`.`T_LOG_XIFENFEI` : Data structure corruption

Schema mismatch (Table has ROW_TYPE_DYNAMIC row format, .ibd file has ROW_TYPE_COMPACT row format.) 這種錯誤是由於row_format設置不正確導致,重新創建表使用正確的row_format然后執行discard和import操作.
Index corrupt: Externally stored column(4) has a reference length of 4 in the cluster index PRIMARY 這種錯誤是由於表的創建語句和ibd中記錄數據不匹配,主要是由於創建表語句不完全正確導致,重新獲取正確語句進行恢復
Internal error: Cannot reset LSNs in table `XFF`.`T_LOG_XIFENFEI` : Data structure corruption 這種錯誤是由於ibd文件本身不一致無法使用該方法恢復,對於這類情況使用我們專業的工具進行處理
20211224142855



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM