简体   繁体   中英

mysql dump copy new and changed data to DB

I have a DB which is 60 GB and I have a live DB which is 13 GB , now on the live DB there are some new entries and updated entries too. Consider 13GB DB has same initial data which 60 GB has with some rows updated and last few entries are completely new. No I want to copy that 13 GB to 60 GB. I have the dump but the insert commands and when I try to import it, it shows me the foreign key constrained error and says it cannot delete or update. So I need a query for MySQL import so that it will copy the new data and update the new if any, and also the dump file is regular dump file with create, insert all those and it is not possible to change anything inside it :(

If disk space isn't an issue here's how I would do it:

  1. Take the database offline
  2. If the original dasebase is called stuff, create a new database named stuff_extra
  3. Load the 13 GB dump onto stuff_extra. You'll now have two databases that are identical on schema but differs in some of the data
  4. For each table in stuff
    1. Delete all rows in stuff.table that are also in stuff_extra.table. You could just delete the rows that have changed but I think this is as fast. Use multi table delete
    2. Insert all rows in stuff_extra.table into stuff.table. Use insert select

You will now have all rows from stuff_extra in stuff. And all data that was updated has been updated (or really deleted and inserted).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM