Home > database >  Two different libraries with Mysql structure table merging problem for help
Two different libraries with Mysql structure table merging problem for help

Time:10-09

My new white , problem description, now have two MySQL database, each have the same structure of A table, two tables with the same data also have each other without the data, how to merge the two tables of data operation to heavy and there are two tables, merge requirements is given priority to with A table, table B if the records in the primary key in the table does not exist, it will add to the table A, if there is the reserved table A record of which eventually after merger, the results will also cover table B, to ensure that the two table data are complete and consistent, amount of data about A list of more than 40, can use the workbench import and export operation directly, hope your bosses directions,

CodePudding user response:

One-time merger
1, can use the mysql replication copy the data to the specified database instance, operation steps, find to merge table, right-click, find "to copy to a different table primary key/database", choose the object library need to be migrated, copy the past;
2,
Insert into a
Select * from b where id not in (select id from a);

Incremental merger
1, can pass the kettel incremental data to the target database instance;
2, the target repository every time insert data
Insert into a
Select * from b where id not in (select id from a);
  • Related