* 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 :)
《零基础学习MySQL》视频课程
戳此小程序即可直达腾讯课堂
或复制链接在浏览器中打开
https://ke.qq.com/course/4333819
文章推荐:
点击文末“阅读原文”直达老叶专栏