最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MySQL單表ibd文件恢復(fù)方法詳解

 更新時(shí)間:2012年11月12日 10:15:00   作者:  
隨著innodb的普及,innobackup也成為了主流備份方式。物理備份對(duì)于新建slave,全庫(kù)恢復(fù)的需求都能從容應(yīng)對(duì);但當(dāng)面臨單表數(shù)據(jù)誤刪,或者單表誤drop的情況,如果使用物理全備進(jìn)行恢復(fù)呢
前言:
隨著innodb的普及,innobackup也成為了主流備份方式。物理備份對(duì)于新建slave,全庫(kù)恢復(fù)的需求都能從容應(yīng)對(duì)。
但當(dāng)面臨單表數(shù)據(jù)誤刪,或者單表誤drop的情況,如果使用物理全備進(jìn)行恢復(fù)呢?
下文將進(jìn)行詳細(xì)分析。
恢復(fù)過(guò)程中需要用到的工具,percona data recover tool : https://launchpad.net/percona-innodb-recovery-tool

情況一:誤刪部分?jǐn)?shù)據(jù),需要用最近一次備份覆蓋
來(lái)自同一臺(tái)機(jī)器的ibd恢復(fù)覆蓋,且備份后table沒(méi)有被recreate過(guò)。
這種情況是最簡(jiǎn)單的,備份時(shí)的ibd文件(后稱老ibd)中的space id和index id 與 新ibd的space id 和index id一致。
且和ibdata文件中的space id和index id一致。因此,物理文件可以直接覆蓋做恢復(fù)。
以下是詳細(xì)步驟

Step -1 : 物理備份
innobackupex --defaults-file=/usr/local/mysql3321/my.cnf --socket=/xfs/mysql3321/mysql.sock --user=root --password=password /xfs/backup/
Step 0 : apply log
innobackupex --apply-log --defaults-file=/usr/local/mysql3321/my.cnf /xfs/backup/2012-10-17_11-29-20/
Step 1 : 備份現(xiàn)在的ibd文件(可選)
cp -a testibd.ibd testibd.bak
Step 2 : 舍棄現(xiàn)在ibd文件
mysql> alter table testibd discard tablespace
Step 3 : 復(fù)制備份ibd文件
shell> cp /xfs/backup/2012-10-17_11-29-20/test/testibd.ibd /xfs/mysql3321/test/
shell> chown mysql:mysql /xfs/mysql3321/test/testibd.ibd
Step 4 : 導(dǎo)入ibd文件
mysql> alter table testibd import tablespace

情況二:誤刪 table,表結(jié)構(gòu)已經(jīng)被drop了
這種情況稍復(fù)雜,不過(guò)恢復(fù)過(guò)程還是比較容易操作的。由于table被drop后的space id會(huì)留空因此備份文件的space id不會(huì)被占用。
我們只需要重建表結(jié)構(gòu),然后把ibdata中該表的space id還原,物理文件可以直接覆蓋做恢復(fù)了。

Step 1 : 重建表
mysql> create table testibd (UserID int);
Step 2 : 關(guān)閉mysql服務(wù)(必須)
shell> service mysqld3321 stop
Step 3: 準(zhǔn)備ibd文件 apply log
shell> innobackupex --apply-log --defaults-file=/usr/local/mysql3321/my.cnf /xfs/backup/2012-10-17_11-29-20/
Step 4 : 備份現(xiàn)在的ibd文件(可選)
cp -a testibd.ibd testibd.bak
Step 5 : 復(fù)制備份ibd文件
shell> cp -a /xfs/backup/2012-10-17_11-29-20/test/testibd.ibd /xfs/mysql3321/test/
shell> chown mysql:mysql /xfs/mysql3321/test/testibd.ibd
Step 6 : 使用percona recovery tool 修改ibdata
shell> /root/install/percona-data-recovery-tool-for-innodb-0.5/ibdconnect -o /xfs/mysql3321/ibdata1 -f /xfs/mysql3321/test/testibd.ibd -d test -t testibd
復(fù)制代碼 代碼如下:

Initializing table definitions...
Processing table: SYS_TABLES
- total fields: 10
- nullable fields: 6
- minimum header size: 5
- minimum rec size: 21
- maximum rec size: 555
Processing table: SYS_INDEXES
- total fields: 9
- nullable fields: 5
- minimum header size: 5
- minimum rec size: 29
- maximum rec size: 165
Setting SPACE=1 in SYS_TABLE for `test`.`testibd`
Check if space id 1 is already used
Page_id: 8, next page_id: 4294967295
Record position: 65
Checking field lengths for a row (SYS_TABLES): OFFSETS: 16 8 50 3 2 0 0 0 0 0
Db/table: infimum
Space id: 1768842857 (0x696E6669)
Next record at offset: 8D
Record position: 8D
Checking field lengths for a row (SYS_TABLES): OFFSETS: 16 11 17 24 32 36 40 48 52 52
Db/table: SYS_FOREIGN
Space id: 0 (0x0)
Next record at offset: D5
Record position: D5
Checking field lengths for a row (SYS_TABLES): OFFSETS: 16 16 22 29 37 41 45 53 57 57
Db/table: SYS_FOREIGN_COLS
Space id: 0 (0x0)
Next record at offset: 122
Record position: 122
Checking field lengths for a row (SYS_TABLES): OFFSETS: 16 12 18 25 33 37 41 49 53 53
Db/table: test/testibd
Space id: 2 (0x2)
Next record at offset: 74
Space id 1 is not used in any of the records in SYS_TABLES
Page_id: 8, next page_id: 4294967295
Record position: 65
Checking field lengths for a row (SYS_TABLES): OFFSETS: 16 8 50 3 2 0 0 0 0 0
Db/table: infimum
Space id: 1768842857 (0x696E6669)
Next record at offset: 8D
Record position: 8D
Checking field lengths for a row (SYS_TABLES): OFFSETS: 16 11 17 24 32 36 40 48 52 52
Db/table: SYS_FOREIGN
Space id: 0 (0x0)
Next record at offset: D5
Record position: D5
Checking field lengths for a row (SYS_TABLES): OFFSETS: 16 16 22 29 37 41 45 53 57 57
Db/table: SYS_FOREIGN_COLS
Space id: 0 (0x0)
Next record at offset: 122
Record position: 122
Checking field lengths for a row (SYS_TABLES): OFFSETS: 16 12 18 25 33 37 41 49 53 53
Db/table: test/testibd
Space id: 2 (0x2)
Updating test/testibd (table_id 17) with id 0x01000000
SYS_TABLES is updated successfully
Initializing table definitions...
Processing table: SYS_TABLES
- total fields: 10
- nullable fields: 6
- minimum header size: 5
- minimum rec size: 21
- maximum rec size: 555
Processing table: SYS_INDEXES
- total fields: 9
- nullable fields: 5
- minimum header size: 5
- minimum rec size: 29
- maximum rec size: 165
Setting SPACE=1 in SYS_INDEXES for TABLE_ID = 17
Page_id: 11, next page_id: 4294967295
Record position: 65
Checking field lengths for a row (SYS_INDEXES): OFFSETS: 15 8 50 7 2 0 0 0 0
TABLE_ID: 3798561113125514496
SPACE: 1768842857
Next record at offset: 8C
Record position: 8C
Checking field lengths for a row (SYS_INDEXES): OFFSETS: 15 8 16 22 29 35 39 43 47
TABLE_ID: 11
SPACE: 0
Next record at offset: CE
Record position: CE
Checking field lengths for a row (SYS_INDEXES): OFFSETS: 15 8 16 22 29 36 40 44 48
TABLE_ID: 11
SPACE: 0
Next record at offset: 111
Record position: 111
Checking field lengths for a row (SYS_INDEXES): OFFSETS: 15 8 16 22 29 36 40 44 48
TABLE_ID: 11
SPACE: 0
Next record at offset: 154
Record position: 154
Checking field lengths for a row (SYS_INDEXES): OFFSETS: 15 8 16 22 29 35 39 43 47
TABLE_ID: 12
SPACE: 0
Next record at offset: 22C
Record position: 22C
Checking field lengths for a row (SYS_INDEXES): OFFSETS: 15 8 16 22 29 44 48 52 56
TABLE_ID: 17
SPACE: 2
Updating SPACE(0x00000001 , 0x01000000) for TABLE_ID: 17
sizeof(s)=4
Next record at offset: 74
SYS_INDEXES is updated successfully

Step 7 : 使用percona recovery tool 重新checksum ibdata
重復(fù)執(zhí)行以下命令,直到程序沒(méi)有輸出為止。
shell> /root/install/percona-data-recovery-tool-for-innodb-0.5/innochecksum -f /xfs/mysql3321/ibdata1
復(fù)制代碼 代碼如下:

page 8 invalid (fails old style checksum)
page 8: old style: calculated = 0xF4AD74CB; recorded = 0xEECB309D
fixing old checksum of page 8
page 8 invalid (fails new style checksum)
page 8: new style: calculated = 0x6F0C29B4; recorded = 0x3D02308C
fixing new checksum of page 8
page 11 invalid (fails old style checksum)
page 11: old style: calculated = 0x3908087C; recorded = 0xF9E8D30C
fixing old checksum of page 11
page 11 invalid (fails new style checksum)
page 11: new style: calculated = 0xB26CFD77; recorded = 0xDB25D39D
fixing new checksum of page 11

Step 8 : 啟動(dòng)mysql服務(wù)
shell> service mysqld3321 start

相關(guān)文章

  • centos下mysql主從復(fù)制設(shè)置詳解

    centos下mysql主從復(fù)制設(shè)置詳解

    centos5.4下mysql主從復(fù)制步驟詳解,大家參考使用吧
    2013-12-12
  • Mysql如何在linux中實(shí)現(xiàn)定時(shí)備份

    Mysql如何在linux中實(shí)現(xiàn)定時(shí)備份

    這篇文章主要介紹了Mysql如何在linux中實(shí)現(xiàn)定時(shí)備份,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • mysql之?dāng)?shù)據(jù)舊表導(dǎo)新表的實(shí)現(xiàn)示例

    mysql之?dāng)?shù)據(jù)舊表導(dǎo)新表的實(shí)現(xiàn)示例

    在MySQL中,可以通過(guò)INSERT INTO...SELECT * FROM...語(yǔ)句輕松復(fù)制兩個(gè)結(jié)構(gòu)相同或目標(biāo)表包含源表所有列的表中的數(shù)據(jù),本文就來(lái)介紹一下mysql之?dāng)?shù)據(jù)舊表導(dǎo)新表的實(shí)現(xiàn)示例,感興趣的可以了解一下
    2024-10-10
  • MySQL的Grant命令詳解

    MySQL的Grant命令詳解

    mysql中可以通過(guò)Grant命令為數(shù)據(jù)庫(kù)賦予用戶權(quán)限,這里簡(jiǎn)單介紹下Grant的使用方法,需要的朋友可以參考下
    2013-10-10
  • Linux下Mysql5.6 二進(jìn)制安裝過(guò)程

    Linux下Mysql5.6 二進(jìn)制安裝過(guò)程

    這篇文章主要介紹了Linux下Mysql5.6 二進(jìn)制安裝過(guò)程,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-06-06
  • mysql now()函數(shù)調(diào)用系統(tǒng)時(shí)間不對(duì)的解決方法

    mysql now()函數(shù)調(diào)用系統(tǒng)時(shí)間不對(duì)的解決方法

    mysql的now()函數(shù)與實(shí)際時(shí)間不符,本文就詳細(xì)的介紹一下mysql now()函數(shù)調(diào)用系統(tǒng)時(shí)間不對(duì)的解決方法,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2023-05-05
  • mysql 8.0 安裝配置方法教程

    mysql 8.0 安裝配置方法教程

    這篇文章主要為大家分享了mysql 8.0安裝配置方法圖文教程,感興趣的朋友可以參考一下
    2016-11-11
  • MySQL中ON DUPLICATE KEY UPDATE語(yǔ)句的使用

    MySQL中ON DUPLICATE KEY UPDATE語(yǔ)句的使用

    INSERT INTO ... ON DUPLICATE KEY UPDATE?是一個(gè)強(qiáng)大的SQL語(yǔ)句,它結(jié)合了插入新記錄和更新已存在記錄的功能于一體,本文就來(lái)介紹一下MySQL中ON DUPLICATE KEY UPDATE語(yǔ)句的使用,感興趣的可以了解一下
    2024-08-08
  • MySQL中使用正則表達(dá)式詳情

    MySQL中使用正則表達(dá)式詳情

    這牌你文章主要給大家分享的是MySQL中使用正則表達(dá)式詳情,MySQL中支持正則表達(dá)式匹配,在復(fù)雜的過(guò)濾條件中,可以考慮使用正則表達(dá)式。使用正則表達(dá)式需要掌握一些正則表達(dá)式的語(yǔ)法和指令,下面來(lái)看看文章的詳細(xì)內(nèi)容介紹吧,希望對(duì)你有所幫助
    2021-11-11
  • linux系統(tǒng)中mysql數(shù)據(jù)庫(kù)的導(dǎo)入和導(dǎo)出

    linux系統(tǒng)中mysql數(shù)據(jù)庫(kù)的導(dǎo)入和導(dǎo)出

    本文給大家簡(jiǎn)單記錄了一下在linux系統(tǒng)中mysql數(shù)據(jù)庫(kù)的導(dǎo)入和導(dǎo)出的方法,有相同需求的小伙伴可以參考下
    2016-02-02

最新評(píng)論

扬中市| 家居| 古蔺县| 乌拉特中旗| 德保县| 府谷县| 柯坪县| 呼图壁县| 潜山县| 建湖县| 佛教| 微山县| 邓州市| 潼关县| 太康县| 康保县| 荆州市| 桂林市| 杂多县| 资溪县| 宜川县| 鄱阳县| 惠州市| 高州市| 大邑县| 珠海市| 江北区| 卫辉市| 阳东县| 仁化县| 东乡县| 遂昌县| 江永县| 微山县| 舟山市| 郁南县| 大新县| 石城县| 东兴市| 临朐县| 敖汉旗|