How can I restore a single column of a single MySQL table?

I have a database in which there is one table where one column has invalid data.

I also have a backup of said database of a few days before. In that backup, that column still has the valid data. But other tables in that database are already incredibly outdated.

So, a full rollback to that backup is not an option. Rather, I would like to only import that single, corrupted column from the backup into the current database.

The live database has also accumulated a few new, valid rows in that table. Obviously, we would like those to be preserved.

I can't think of a way that doesn't involve heavy, manual editing. Can this be automated?


Solution 1:

Yes you can. Import that data from the backup into a temporary table and do something like this:

UPDATE target_schema.target_table tt
JOIN source_schema.source_table ss ON tt.t_id = ss.s_id
SET tt.target_column = ss.source_column;