How to undo the effect of the last mysql query executed

I just ran a command

update sometable set col = '1'; 

by mistake without specifying the where clause. Can I restore a previous version of a table?

+7
mysql rollback
source share
3 answers

If you not...

  • Started a transaction before running the request and ...
  • Did not complete the transaction

... then no, you're out of luck by banning any backups of previous versions of the database that you could do yourself.

(If you do not use transactions when manually entering queries, you may want to prevent headaches in the future, such as those that you probably now have invaluable in mitigating the implemented error 5 seconds later.)

+9
source share

Consider including sql_safe_updates in the future if you are worried about doing this again.

 SET SESSION sql_safe_updates = 1 
+2
source share

Not. MySQL has transaction support for some types of tables, but since you are asking this question, I bet you are not using it.

Everyone does it once. When you do this twice, you have to worry :)

+1
source share

All Articles