Post by Ralph SmithI thought about mysqldump but that would overwrite the data in one of the databases.
It doesn't overwrite if you make sure that you dump only the
insert-queries (I think there was some parameter to enable this) or
manually edit the file to contain only insert queries.
Insert queries never overwrite anything. They will either create a row
or fail.
If you are using the same unique index in both databases, the insert
query will fail when it encounters such a query. There are solutions and
workarounds for this also, depending on what should be done when that
happens.
One solution is also to dump the whole database and then create a new
database on the server where the data should be copied. By importing the
data there, you have both of the databases on the same server, which
could make merging more easy (basicly it can be done with a single query
if you are using auto_increment).
Example:
mysql> create database a;
Query OK, 1 row affected (0.01 sec)
mysql> use a
mysql> create table table1(id int unsigned auto_increment primary key,
name text);
Query OK, 0 rows affected (0.01 sec)
mysql> insert into table1(name) values('test1'),('test2'),('test3');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> create database b;
Query OK, 1 row affected (0.00 sec)
mysql> use b
Database changed
mysql> create table table1(id int unsigned auto_increment primary key,
name text);
Query OK, 0 rows affected (0.01 sec)
mysql> insert into table1(name) values('Jack'),('Jill'),('Bill');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from a.table1;
+----+-------+
| id | name |
+----+-------+
| 1 | test1 |
| 2 | test2 |
| 3 | test3 |
+----+-------+
3 rows in set (0.00 sec)
mysql> select * from b.table1;
+----+------+
| id | name |
+----+------+
| 1 | Jack |
| 2 | Jill |
| 3 | Bill |
+----+------+
3 rows in set (0.00 sec)
mysql> insert into a.table1(name) select name from b.table1;
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from a.table1;
+----+-------+
| id | name |
+----+-------+
| 1 | test1 |
| 2 | test2 |
| 3 | test3 |
| 4 | Jack |
| 5 | Jill |
| 6 | Bill |
+----+-------+
6 rows in set (0.00 sec)