How to rollback the effect of last executed mysql query

Rohit Banga picture Rohit Banga · May 15, 2010 · Viewed 26.6k times · Source

I just ran a command

update sometable set col = '1';

by mistake without specifying the where condition. Is it possible to recover the previous version of the table?

Answer

Amber picture Amber · May 15, 2010

Unless you...

  1. Started a transaction before running the query, and...
  2. Didn't already commit the transaction

...then no, you're out of luck, barring any backups of previous versions of the database you might have made yourself.

(If you don't use transactions when manually entering queries, you might want to in the future to prevent headaches like the one you probably have now. They're invaluable for mitigating the realized-5-seconds-later kind of mistake.)