利用innobackupex備份集恢復指定庫

skzhuga發表於2019-01-07

1.源庫匯出表結構

mysqldump -uroot -p --no-data zabbix > info.sql


2.建立要恢復的庫、表

mysql> create database zabbix character set utf8 collate utf8_bin;

mysql> use zabbix;

mysql> source info.sql


3.檢視外來鍵約束

mysql> SELECT  @@FOREIGN_KEY_CHECKS;

+----------------------+

| @@FOREIGN_KEY_CHECKS |

+----------------------+

|                    1 |

+----------------------+

1 row in set (0.00 sec)


檢視要遷移的表是否有外來鍵約束:

mysql> select * from information_schema.TABLE_CONSTRAINTS where table_schema = 'zabbix' and constraint_type = 'FOREIGN KEY';

如果有的話,禁用外來鍵:

mysql> SET FOREIGN_KEY_CHECKS=0;

Query OK, 0 rows affected (0.00 sec)


4.庫中的表進行discard tablespace

mysql> select concat('alter table ',table_name,' discard tablespace;') from information_schema.tables  where table_schema = 'zabbix';

mysql>  alter table acknowledges discard tablespace; 

Query OK, 0 rows affected (0.00 sec)


mysql>  alter table actions discard tablespace;

Query OK, 0 rows affected (0.00 sec)

......

然後重新啟用外來鍵約束:

mysql> SET FOREIGN_KEY_CHECKS=1;

Query OK, 0 rows affected (0.00 sec)


5.將apply-log後的備份集中表的ibd檔案複製到資料目錄下並修改許可權:

cp *.ibd /opt/app/mysql/mysql5722/data/zabbix/

chown -R mysql.mysql /opt/app/mysql/mysql5722/data/zabbix/*


6.庫中的表進行import tablespace

mysql> select concat('alter table ',table_name,' import tablespace;') from information_schema.tables where table_schema = 'zabbix';

如果報錯:ERROR 1808 (HY000): Schema mismatch (Table has ROW_TYPE_DYNAMIC row format, .ibd file has ROW_TYPE_COMPACT row format.)

則修改表的row_format:

mysql> select concat('alter table ',table_name,' row_format=compact;') from information_schema.tables where table_schema = 'zabbix';

注意:修改表的row_format後,要重新進行第5步


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31544156/viewspace-2374677/,如需轉載,請註明出處,否則將追究法律責任。

相關文章