ha*****@gmail.com wrote:
HI, I got a problem about restoring data in mysql:
I have 2 or more PCs installed with mysql database, with same or almost
same table structure, but with different data. Can I combine those
data into one database?
suppose: one pc server has main database with main data, another pc has
some special data, I need combine those data into the main database, if
main database already have the data, then dont' change it, if main
database doesn't have the data, then append it into main database.
Yes, you can use `databasename`.`tablename` in SQL statements, so you
should be able to do this:
INSERT IGNORE INTO maindatabase.table1 (column1, column1, column3)
SELECT column1, column2, column3
FROM specialdatabase.table1;
The "IGNORE" keyword means that if the operation gets a duplicate key
error as it attempts to insert a row, do not abort (but that row is
still not inserted). So the records that succeed will be only those
that have distinct values for the primary key.
Though this doesn't detect cases where you have rows that are the "same"
data but have distinct primary key values in the special database versus
the main database. That's harder to detect automatically.
Regards,
Bill K.