php 如何撤消phpmyadmin中的查询执行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4836455/
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 undo a query execution in phpmyadmin
提问by DEVOPS
How to undo a query execution in phpmyadmin.
如何在 phpmyadmin 中撤消查询执行。
Any rollback functionality is there? any body knows the solution kindly help me?
有任何回滚功能吗?任何人都知道解决方案请帮助我?
回答by Mark Byers
If the statement is still running you can use KILL QUERY <thread_id>
.
如果语句仍在运行,您可以使用KILL QUERY <thread_id>
.
If the statement has completed but you have not yet committed the transaction you can use ROLLBACK
.
如果语句已完成但您尚未提交事务,则可以使用ROLLBACK
.
If the statement has completed and the transaction is already committed (or you didn't start a transaction) then restore the data from your most recent backup.
如果语句已完成并且事务已经提交(或者您没有启动事务),则从最近的备份中恢复数据。
Also here are some tips advice in order to prevent this type of situation happening in the first place:
这里还有一些提示建议,以防止这种情况发生:
- When writing a DELETE or UPDATE always write the WHERE clause first so that you don't forget it.
- Test your WHERE clause in a SELECT statement to make sure you are updating the correct rows.
- If you know you should only be updating one row then you can add LIMIT 1 to your UPDATE statement. Then if despite using the above techniques you still have an error at least only one row will be affected, not the entire database.
- 在编写 DELETE 或 UPDATE 时,始终首先编写 WHERE 子句,以免忘记它。
- 在 SELECT 语句中测试您的 WHERE 子句以确保您正在更新正确的行。
- 如果您知道您应该只更新一行,那么您可以将 LIMIT 1 添加到您的 UPDATE 语句中。然后,如果尽管使用了上述技术,您仍然有错误,至少只有一行会受到影响,而不是整个数据库。
回答by Nanne
You can go to the 'processes' page and press 'kill'
您可以转到“进程”页面并按“杀死”
回答by ayush
if you deleted something then i dont think its going to come back unless you had a backup.I know in sql you can sometimes get away will the ROLLBACK call before you commit to a series of SQL commands but Only in transactions, and you have to have them started first (which phpMyAdmin doesn't use).
如果你删除了一些东西,那么我不认为它会回来,除非你有备份。我知道在 sql 中你有时可以在你提交一系列 SQL 命令之前摆脱 ROLLBACK 调用,但只在事务中,你必须让它们先启动(phpMyAdmin 不使用)。
回答by Mark Baker
If you need the ability to restore previous data back prior to a committed update, then you could refactor your database using update and delete triggers to store the old data in an archive table with a current date/timestamp or (preferably) a transaction id value (and ensure that inserts always store a current date/timestamp or transaction id value)... effectively maintaining an entire history of every change made to your database. Beware, your database will grow at an incredible rate... this is only really a solution for mission-critical data where the history is essential, because it takes a lot of effort to implement, and a lot of expensive disk space to maintain. Even then, it can get very complex if there have been subsequent updates to the affected data; and you may need to "lose" those when reverting to a previous history.
如果您需要在提交更新之前恢复先前数据的能力,那么您可以使用更新和删除触发器重构您的数据库,以将旧数据存储在具有当前日期/时间戳或(最好)事务 ID 值的存档表中(并确保插入始终存储当前日期/时间戳或事务 ID 值)...有效地维护对数据库所做的每次更改的完整历史记录。请注意,您的数据库将以令人难以置信的速度增长......这只是历史至关重要的任务关键型数据的真正解决方案,因为它需要大量的努力来实现,并且需要大量昂贵的磁盘空间来维护。即便如此,如果受影响的数据有后续更新,它也会变得非常复杂;并且您可能需要在恢复到以前的历史记录时“丢失”它们。
I can only think of a very few systems that implement this type of history maintenance... eg Oracle Financials or HR.
我只能想到实现这种类型的历史维护的少数系统……例如 Oracle 财务或人力资源。
ALternatively, there are some databases (I used to work with the old DEC RDBMS) that can maintain RUJs (Run Unit Journals) which can then be used to restore from a backup and up to a set time/transaction. However MySQL doesn't fall into this category. Again, it requires a lot of disk space, and is only practical when you do regular backups of your data, and the recovery process is more complex. MySQL (as far as I'm aware) doesn't support this feature.
或者,有一些数据库(我曾经使用旧的 DEC RDBMS)可以维护 RUJ(运行单元日志),然后可用于从备份恢复到设定的时间/事务。但是 MySQL 不属于这一类。同样,它需要大量磁盘空间,只有在您定期备份数据时才实用,而且恢复过程更加复杂。MySQL(据我所知)不支持此功能。
For most people, the more practical approach is a simple restore from backup, possibly followed by some manual recreation. Unfortunately, most people these days don't even take backups.
对于大多数人来说,更实用的方法是从备份中进行简单的恢复,然后可能会进行一些手动恢复。不幸的是,如今大多数人甚至不进行备份。
回答by Rich
If you've already committed the transaction, there is no way of “undoing” it, I'm afraid. That's one of the core principles of ACID. If you haven't committed it: just do a rollback
, and you're fine.
如果您已经提交了事务,恐怕没有办法“撤消”它。这是 ACID 的核心原则之一。如果您还没有提交:只需执行一个rollback
,就可以了。
You'll need to restore you data from a backup – or if the query is running, try what Mark Byers suggested, using kill query
.
您需要从备份中恢复数据——或者如果查询正在运行,请尝试 Mark Byers 的建议,使用kill query
.