MySQL誤刪除InnoDB資料檔案恢複

來源:互聯網
上載者:User

MySQL誤刪除InnoDB資料檔案恢複

錯誤重現:
 使用rm -f ib*刪除資料檔案和重做記錄檔。這時mysql進程還存在,mysql還能正常使用。
 
檔案恢複:
  1:尋找mysqld的進程號。
# netstat -ntpl | grep mysqld
 tcp    0  0 0.0.0.0:3306  0.0.0.0:*      LISTEN  12147/mysqld

2:利用進程號尋找如下檔案。
# ll /proc/12147/fd | egrep 'ib_|ibdata'
  lrwx------ 1 root root 64 Jun 18 09:23 10 -> /mydata/ib_logfile1 (deleted)
  lrwx------ 1 root root 64 Jun 18 09:23 4 -> /mydata/ibdata1 (deleted)
  lrwx------ 1 root root 64 Jun 18 09:23 9 -> /mydata/ib_logfile0 (deleted)

3:添加鎖,使資料庫沒有寫入操作。
sql> flush tables with read lock;

4:輸入以下命令,讓髒頁儘快刷入到磁碟。
sql> set global innodb_max_dirty_pages_pct=0;

5:查看innodb狀態資訊,確認髒頁已經刷入磁碟,比對如下數值:

6:確認完後,就可以進行恢複操作了,把之前記錄的刪除檔案複製到原來目錄下。
# cd /proc/12147/fd 
# cp 10 /mydata/ib_logfile1
# cp 4 /mydata/ibdata1
# cp 9 /mydata/ib_logfile0

7:重啟mysqld服務既可。

本文永久更新連結地址:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.