1

I'm trying come up with the best method of synchronizing particular rows of 2 different database tables. So, for example there's 2 product tables in different databases as such...

Origin Database

product{
    merchant_id,
    product_id,
    ... additional fields
}

Destination Database

product{
    merchant_id
    product_id
    ... additional fields
}

So, the database schema is the same for both. However I'm looking to select records with a particular merchant_id, remove all records from the destination table that have that merchant_id and replace those records with records from the origin database of the same merchant_id.

My first thought was using mysqldump, parsing out the create table statements, and only running the Insert Statements. Seems like a pain though. So I was wondering if there is a better technique to do this.

I would think mysql has some method of creating INSERT statements as output from a SELECT statement, so you can define how to insert specific record information into a new db.

Any help would be appreciated, thank you much.

1 Answer 1

1

phpMyAdmin has part of this capability: You can run a query and then export the results of that query into a file containing CREATE statements.

Update: And mysqldump has it too: Link

mysqldump -u username -p --where="id='merchant_id'" databasename

In regards to replacing merchant IDs, that part I don't entirely understand yet. You may be better off doing a manual search+replace on them. Can you make a real life example of two such records?

2
  • Yeah I know mysqldump has that functionality, I was looking for a slicker solution, other wise I have to parse through file to remove all CREATE TABLE statements. I'm was thinking there might be a method to only get the INSERT statements.
    – Aglystas
    May 12, 2010 at 18:17
  • 1
    @Aglystas Why not remove the CREATE TABLEs using --no-create-info? dev.mysql.com/doc/refman/5.1/en/…
    – Pekka
    May 12, 2010 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.