利用innobackupex备份集恢复指定库

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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31544156/viewspace-2374677/

你可能感兴趣的:(数据库,运维)