7

万答#14,xtrabackup8.0怎么恢复单表

 2 years ago
source link: https://segmentfault.com/a/1190000041127543
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

万答#14,xtrabackup8.0怎么恢复单表

发布于 10 分钟前

欢迎来到 GreatSQL社区分享的MySQL技术文章,如有疑问或想学习的内容,可以在下方评论区留言,看到后会进行解答

  • GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源。

GreatSQL 8.0.25 InnoDB

1.备份,导出单表, test.t_user

/usr/bin/xtrabackup -uroot -p'GreatSQL' -S /data/GreatSQL/mysql.sock --tables='test.t_user' --backup --target-dir=/data/backup

2.恢复备份

xtrabackup --prepare --export --target-dir=/data/backup

3.建测试表

[root@GreatSQL][test02]>CREATE TABLE `t_user` (
    ->   `id` bigint NOT NULL AUTO_INCREMENT,
    ->   `name` varchar(255) DEFAULT NULL,
    ->   `age` tinyint DEFAULT NULL,
    ->   `create_time` datetime DEFAULT NULL,
    ->   `update_time` datetime DEFAULT NULL,
    ->   PRIMARY KEY (`id`),
    ->   KEY `idx_name` (`name`),
    ->   KEY `idx_age` (`age`)
    -> ) ENGINE=InnoDB AUTO_INCREMENT=1091002 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Query OK, 0 rows affected (0.16 sec)

4.卸载新表表空间

[root@GreatSQL][test02]>ALTER table t_user discard tablespace;
Query OK, 0 rows affected (0.11 sec)

5.拷贝备份的t_user文件

[root@localhost test]# cd /data/backup/test/
[root@localhost test2]# cp * /data/GreatSQL/test02/
[root@localhost test2]# ll
-rw-r--r-- 1 root root      964 Nov 24 04:12 t_user.cfg
-rw-r----- 1 root root 18874368 Nov 24 04:10 t_user.ibd

6.挂载新表表空间

[root@GreatSQL][test02]>ALTER TABLE t_user import tablespace;
Query OK, 0 rows affected, 1 warning (0.47 sec)

7.查询恢复数据

[root@GreatSQL][test02]>select count(*) from test02.t_user;
+----------+
| count(*) |
+----------+
|    91002 |
+----------+
1 row in set (0.10 sec)
# 旧表的数据
[root@GreatSQL][test02]>select count(*) from test.t_user;
+----------+
| count(*) |
+----------+
|    91002 |
+----------+
1 row in set (0.07 sec)

(Wed Nov 24 21:35:57 2021)[root@GreatSQL][test02]>

Enjoy GreatSQL :)

文章推荐:

技术分享 | MGR最佳实践(MGR Best Practice)
https://mp.weixin.qq.com/s/66...

技术分享 | 万里数据库MGR Bug修复之路
https://mp.weixin.qq.com/s/Ia...

Macos系统编译percona及部分函数在Macos系统上运算差异
https://mp.weixin.qq.com/s/jA...

技术分享 | 利用systemd管理MySQL单机多实例
https://mp.weixin.qq.com/s/iJ...

产品 | GreatSQL,打造更好的MGR生态
https://mp.weixin.qq.com/s/By...

产品 | GreatSQL MGR优化参考
https://mp.weixin.qq.com/s/5m...

关于 GreatSQL

GreatSQL是由万里数据库维护的MySQL分支,专注于提升MGR可靠性及性能,支持InnoDB并行查询特性,是适用于金融级应用的MySQL分支版本。

Gitee:
https://gitee.com/GreatSQL/Gr...

GitHub:
https://github.com/GreatSQL/G...

微信&QQ群:

可搜索添加GreatSQL社区助手微信好友,发送验证信息“加群”加入GreatSQL/MGR交流微信群

QQ群:533341697
微信小助手:wanlidbc

本文由博客一文多发平台 OpenWrite 发布!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK