# Merging MySQL databases with xtrabackup

**URL:** <https://forums.percona.com/t/merging-mysql-databases-with-xtrabackup/35662>\
**Category:** Percona XtraDB Cluster\
**Created:** [December 14, 2024, 3:31pm UTC](https://forums.percona.com/t/merging-mysql-databases-with-xtrabackup/35662 "2024-12-14T15:31:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CharlesR](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@CharlesR](https://forums.percona.com/u/CharlesR)\
**Post date:** [December 14, 2024, 3:31pm UTC](https://forums.percona.com/t/merging-mysql-databases-with-xtrabackup/35662/1 "2024-12-14T15:31:31Z")

</div>

Hi,

I have two MySQL 8.4 databases:

Server 1: schema: com  
Server 2: schema: cli

Using xtrabackup, is it possible to merge the two databases into a server 3?

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [December 16, 2024, 2:39am UTC](https://forums.percona.com/t/merging-mysql-databases-with-xtrabackup/35662/2 "2024-12-16T02:39:31Z")

</div>

Hello @CharlesR,  
Yes, this is possible, but it will be extremely tedious, and will require the schema from all tables. Basically the steps will be like this:

1. Take backup of server 1 and specify ‘–databases=com’.
2. Restore this backup using the normal methods and flags
3. Take a backup of server 2, ‘–databases=cli’
4. During the prepare phase of restore, use --export. This prepares all .ibd files for importing into another server. You will have .ibd, and .cfg files for each table.
5. In MySQL, created in #2, create database cli.
6. For each table in cli, CREATE TABLE …; ALTER TABLE … DISCARD TABLESPACE; In shell, copy .ibd and .cfg to $datadir/cli/ chown mysql:mysql .ibd/.cfg file. In MySQL, ALTER TABLE … IMPORT TABLESPACE. SELECT \* FROM … to verify data. Repeat for remaining tables.

Depending on the size of these datasets, you might have an easier, and less error prone time by using [mydumper/myloader](https://github.com/mydumper/mydumper).
