MySQL 如何回滚上次执行的mysql查询的效果
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2839269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to rollback the effect of last executed mysql query
提问by Rohit Banga
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?
错误地没有指定 where 条件。是否可以恢复以前版本的表格?
回答by Amber
Unless you...
除非你...
- Started a transaction before running the query, and...
- 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 transactionswhen 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.)
(如果您在手动输入查询时不使用事务,您可能希望在将来避免像您现在可能遇到的那样的麻烦。它们对于减轻已实现的 5 秒后类型的错误非常宝贵。)
回答by Hammerite
Consider enabling sql_safe_updates
in future if you are worried about doing this kind of thing again.
sql_safe_updates
如果您担心再次执行此类操作,请考虑在将来启用。
SET SESSION sql_safe_updates = 1
回答by Paul Dixon
No. MySQL does have transaction supportfor some table types, but because you're asking this question, I'll bet you're not using it.
不。MySQL 确实对某些表类型有事务支持,但是因为您在问这个问题,所以我敢打赌您没有使用它。
Everybody does this once. It's when you do it twice you have to worry :)
每个人都这样做一次。当你做两次时,你必须担心:)