473,414 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

merging data?


I have two identical databases on two different servers and I need to add the data in tables from
one server to the tables in the other server. Is there a way to do that in mysql?

thanks,
Ralph
Feb 26 '07 #1
3 3859
Ralph Smith wrote:
I have two identical databases on two different servers and I need to add the data in tables from
one server to the tables in the other server. Is there a way to do that in mysql?
In realtime or do you want to do it just one time?

If only one time, you could for example use "mysqldump filename.sql"
to dump the data from other database and then use "mysql < filename.sql"
to import it to the other (You need to add username and other parameters
to those commands also.).

If you are same unique id values in both databases, you need to fix that
also. How to fix it depends again on what you want to do when identical
id values are found. Keep old, overwrite or insert with new id.

If you want to do it in real time, I suggest that you red the MySQL
manual. If I remember correctly there are some ways to do it, but I'm
not familiar with them.
Feb 26 '07 #2
On Mon, 26 Feb 2007 20:55:19 GMT, Aggro <sp**********@yahoo.comwrote:
>Ralph Smith wrote:
>I have two identical databases on two different servers and I need to add the data in tables from
one server to the tables in the other server. Is there a way to do that in mysql?

In realtime or do you want to do it just one time?

If only one time, you could for example use "mysqldump filename.sql"
to dump the data from other database and then use "mysql < filename.sql"
to import it to the other (You need to add username and other parameters
to those commands also.).

If you are same unique id values in both databases, you need to fix that
also. How to fix it depends again on what you want to do when identical
id values are found. Keep old, overwrite or insert with new id.

If you want to do it in real time, I suggest that you red the MySQL
manual. If I remember correctly there are some ways to do it, but I'm
not familiar with them.
I thought about mysqldump but that would overwrite the data in one of the databases. I really need
to append data in tables from one database into identical tables of a database on a different
server. Or maybe there is some way to synchronize 2 databses? I don't need to do it in real time,
just occasionally.

thanks,
Ralph
Feb 27 '07 #3
Ralph Smith wrote:
I 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:
mysqlcreate database a;
Query OK, 1 row affected (0.01 sec)

mysqluse a
mysqlcreate table table1(id int unsigned auto_increment primary key,
name text);
Query OK, 0 rows affected (0.01 sec)

mysqlinsert into table1(name) values('test1'),('test2'),('test3');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysqlcreate database b;
Query OK, 1 row affected (0.00 sec)

mysqluse b
Database changed
mysqlcreate table table1(id int unsigned auto_increment primary key,
name text);
Query OK, 0 rows affected (0.01 sec)

mysqlinsert into table1(name) values('Jack'),('Jill'),('Bill');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysqlselect * from a.table1;
+----+-------+
| id | name |
+----+-------+
| 1 | test1 |
| 2 | test2 |
| 3 | test3 |
+----+-------+
3 rows in set (0.00 sec)

mysqlselect * from b.table1;
+----+------+
| id | name |
+----+------+
| 1 | Jack |
| 2 | Jill |
| 3 | Bill |
+----+------+
3 rows in set (0.00 sec)

mysqlinsert into a.table1(name) select name from b.table1;
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysqlselect * from a.table1;
+----+-------+
| id | name |
+----+-------+
| 1 | test1 |
| 2 | test2 |
| 3 | test3 |
| 4 | Jack |
| 5 | Jill |
| 6 | Bill |
+----+-------+
6 rows in set (0.00 sec)
Feb 27 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Klatuu | last post by:
Whew, I've struggled my way through figuring out how to use XML to transport data..now I can imagine what having a baby is like :) But, I'm stuck now. I generate the XML (single table, no...
3
by: Mike | last post by:
Hi! I also asked this question in C# group with no results: I have 2 datasets loaded with data from two xml files having the same schema. The files contain data from yesterday and today. I'd...
3
by: Patrick | last post by:
I have got 2 XML documents, both of which conform to the same XSD Schema, which define possible optional elements. The 2 XML documents contain 2 disjoint set of XML elements. What is the best,...
2
by: Emmett Power | last post by:
Hi, I have an Access table with a number of records which refer to the same person but with data in different fields. So for example the table would look like this: Name..............Field...
1
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word...
15
by: PRadyut | last post by:
In this code it throws a runtime error on a code access violation . On the line z->data=p->data; while (p!=NULL && q!=NULL) { if (*s==NULL) {
0
by: Mike | last post by:
Hi! I have 2 datasets loaded with data from two xml files having the same schema. The files contain data from yesterday and today. I'd like to merge both datasets in such a way that the resulting...
3
by: Sanjib Biswas | last post by:
Hi All, I am looking for XML merging for the following scenarios. I want to load both the input files and show in the tree viewer and highlight the differences. Now its up to the user to select...
7
by: Jon Vaughan | last post by:
I have 2 datasets , one returned as a dataset from a webservice and one created client side form the same stored procedure that is returned from the webservice. I then try and merge the data, but...
31
by: louishong | last post by:
3rd time posting this as the first two simply disappeared! Here's the issue: We currently run an Access application in the West Coast for tracking resource centric data. For those located in the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.