I want to merge data from one database to another. So I create dump with mysqldump and then import it to another database (with same tables structure). I don't have any problems (such as duplicate entries or something else) in this case.
But I do some merges for testing purposes and I'll do final merge later. So, I want to execute merge (data may be changed) a few times. Notice, my rows in my tables never deletes, only can be inserted or updated.
Can I create mysqldump with ON DUPLICATE option? Or may be I can merge dump that inserts new data and update modified data?
Sure, I can insert ON DUPLICATE in dump manually, but I want to automate merge process.
--replaceis equivalent to doingON DUPLICATE UPDATEon every column. Unfortunately, mysqldump is not designed to update specific columns because of the bulk loading and dumping nature of mysqldump. My answer simply reveals what mysqldump is capable of doing. You would have to write custom code, apart from mysqldump, to doON DUPLICATE UPDATE. – RolandoMySQLDBA Jul 03 '14 at 02:08import it to another database (with same tables structure), then my answer matches the question as posed. In the event of updating a few columns instead of all columns (regardless of matching table structures or not), you have to custom codeON DUPLICATE KEY UPDATE. mysqldump is definitely not the solution in your particular case. I recommend that you post your problem as a separate question. – RolandoMySQLDBA Jul 03 '14 at 02:49REPLACE INTOmight fail because the record cannot be deleted with severing those relationships. If you haveON DELETE CASCADE, then you will empty-out those tables that depend upon the one being updated.REPLACE INTOis quite a dangerous operation. – Christopher Schultz Jul 03 '14 at 20:36REPLACE INTO) can be dangerous and have "surprising" effects. Good answer -- just wanted to add a caveat. – Christopher Schultz Jul 07 '14 at 13:36