温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何利用innobackupex备份集恢复指定库

发布时间:2021-10-27 17:00:44 来源:亿速云 阅读:282 作者:小新 栏目:MySQL数据库

这篇文章主要介绍如何利用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步

以上是“如何利用innobackupex备份集恢复指定库”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI