Search code examples
mysqlbackupdatabase-backups

mysql: restore a value of a column from backup


I'm having trouble. Instead of launchin script

UPDATE table_name SET field=value WHERE id=12345

I launched

UPDATE table_name SET field=value

Database is backuped every day (with mysqldump). What is the simpliest way to restore the value of that column using the backup. obviously I cannot apply that backup dirrectly as database is continiously changed.

Thank you in advance!!


Solution

  • I would create a new table 'table_name2' identical to your 'table_name' but containing the data of your backup.

    Then use this query:

    UPDATE table_name SET
    table_name.field = (SELECT table_name2.field 
                        FROM table_name2 
                        WHERE table_name.id = table_name2.id)