如何回滚上次执行的mysql查询的效果

时间:2022-11-26 00:49:23

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条件。是否有可能恢复该表的先前版本?

3 个解决方案

#1


10  

Unless you...

  1. Started a transaction before running the query, and...
  2. 在运行查询之前启动了一个事务,并且......

  3. Didn't already commit the transaction
  4. 尚未提交交易

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

(如果您在手动输入查询时不使用事务,您可能希望将来能够避免像您现在可能遇到的那样令人头疼。它们对于减轻已实现的5秒钟后的错误非常有用。)

#2


2  

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

#3


1  

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.

不.MySQL确实对某些表类型有事务支持,但因为你问这个问题,我敢打赌你没有使用它。

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

每个人都这样做过一次。这是你两次做的时候你要担心:)

#1


10  

Unless you...

  1. Started a transaction before running the query, and...
  2. 在运行查询之前启动了一个事务,并且......

  3. Didn't already commit the transaction
  4. 尚未提交交易

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

(如果您在手动输入查询时不使用事务,您可能希望将来能够避免像您现在可能遇到的那样令人头疼。它们对于减轻已实现的5秒钟后的错误非常有用。)

#2


2  

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

#3


1  

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.

不.MySQL确实对某些表类型有事务支持,但因为你问这个问题,我敢打赌你没有使用它。

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

每个人都这样做过一次。这是你两次做的时候你要担心:)