天天看點

MySQL(原版)恢複單個InnoDB資料庫表

本文轉自 位鵬飛 51CTO部落格,原文連結:http://blog.51cto.com/weipengfei/933208,如需轉載請自行聯系原作者<b>Percona 中的 xtrabackup 真是個好工具, 簡單的介紹的他的功能:</b>

  1、建立熱備份(主要依靠innodb的 crash recovery 功能)

  2、增量備份

  3、直接對備份檔案壓縮打包

  4、負載小

  在測試最新版本2.0時,發現問題:

   importing  and   exporing  individual tables中這個工具對Oracle 原版的MySQL是不起作用的。

   解釋如下:在原版MySQL中是不能任意移動資料庫的.idb檔案,官方給出的解釋是:the table definition that is stored in the<code>InnoDB</code>shared tablespace includes the database name, and because<code>InnoDB</code>must preserve the consistency of transaction IDs and log sequence numbers. 即:表定義存儲在innodb 中的共享表空間中,事務id 和日志序列号是放在單個的表空間檔案中。(在percona  server 這個限制已經移除)

   經多方咨詢:這個工具對于原版MySQL 還是可以用的。具體如下:

   備份單個表:

   innobackupex --tables-file=/tmp/tables.txt  /path/to/backup

   關鍵是下面這步:

   --export 先使用該選項獲得一個完全獨立的idb檔案(官方未提到)

   innobackupex  --defaults-file=/usr/local/mysql/my.cnf --export  /tmp

   下面是将應用日志而得到一個一緻的備份:

    innobackupex  --defaults-file=/usr/local/mysql/my.cnf --export --apply-log  /path/to/backup

    如果遇到獨立ibd tableid 與共享表空間裡面tableid 不一緻,可能是innodb_import_table_from_xtrabackup 或者是  innodb_expand_import  參數沒有開啟