Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!!

like image 781
Eugeny89 Avatar asked Dec 16 '22 04:12

Eugeny89


1 Answers

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)
like image 165
adrien54 Avatar answered Dec 29 '22 12:12

adrien54