Hey all,

Some rows of a single table in a database that I administer manage to have gone missing. Not that big of a problem: I have a backup.

The issue is that there has been more information added since the old data was lost, so I can't do a wholesale replacement. I've isolated the range of rows that were removed based on the primary key, but I'm not sure about the rest of the steps:

1) Export the rows based on the unique row id number;

2) Re-import the old rows without disturbing the new data.

Anyone have some wisdom for me?

Many thanks,

It all dependes. Does your table has relations to other tables? Is the primary key used as a foreign key elsewhere? Do you have orphaned records in relations?
If all this is no problem, the easiest way would be this:
Restore the backup table in a backup database (here called backup).

insert ignore into mytable
select * from `backup`.mytable;

That way no new information will be overwritten, and all lost records will be restored.

Hey smatscheff,

This looks like it'll do the trick. I'll run it now on a test DB and see how that works out. Many thanks for your advice. I'll mark this solved as soon as I get the records copied over.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.