How to rollback the effect of last executed mysql query

给你一囗甜甜゛ 提交于 2019-12-12 10:36:26

问题


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?


回答1:


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.)




回答2:


Consider enabling sql_safe_updates in future if you are worried about doing this kind of thing again.

SET SESSION sql_safe_updates = 1



回答3:


No. MySQL does have transaction support for some table types, but because you're asking this question, I'll bet you're not using it.

Everybody does this once. It's when you do it twice you have to worry :)



来源:https://stackoverflow.com/questions/2839269/how-to-rollback-the-effect-of-last-executed-mysql-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!