MySQL 如何恢复mysql中刚刚删除的行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6924823/
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 recover just deleted rows in mysql?
提问by kinkajou
Is it possible to restore table to last time with data if all data was deleted accidentally.
如果所有数据都被意外删除,是否可以将表恢复到上次数据。
回答by Mihai Iorga
There is another solution, if you have binary logs active on your server you can use mysqlbinlog
还有另一种解决方案,如果您的服务器上有活动的二进制日志,则可以使用 mysqlbinlog
generate a sql file with it
用它生成一个sql文件
mysqlbinlog binary_log_file > query_log.sql
then search for your missing rows. If you don't have it active, no other solution. Make backups next time.
然后搜索您丢失的行。如果您没有激活它,则没有其他解决方案。下次备份。
回答by Aardvark27
Sort of. Using phpMyAdmin I just deleted one row too many. But I caught it before I proceeded and had most of the data from the delete confirmation message. I was able to rebuild the record. But the confirmation message truncated some of a text comment.
有点。使用 phpMyAdmin 我只是删除了太多行。但是我在继续之前就发现了它,并从删除确认消息中获得了大部分数据。我能够重建记录。但是确认消息截断了一些文本评论。
Someone more knowledgeable than I regarding phpMyAdmin may know of a setting so that you can get a more complete echo of the delete confirmation message. With a complete delete message available, if you slow down and catch your error, you can restore the whole record.
比我更了解 phpMyAdmin 的人可能知道一个设置,以便您可以获得更完整的删除确认消息回声。有了完整的删除消息,如果您放慢速度并发现错误,您就可以恢复整个记录。
(PS This app also sends an email of the submission that creates the record. If the client has a copy, I will be able to restore the record completely)
(PS这个app也会发邮件创建记录的提交,如果客户端有副本,我就可以完全恢复记录)
回答by Shamim Hafiz
As Mitch mentioned, backing data up is the best method.
正如米奇所说,备份数据是最好的方法。
However, it maybe possible to extract the lost data partially depending on the situation or DB server used. For most part, you are out of luck if you don't have any backup.
但是,根据情况或使用的数据库服务器,可能可以部分提取丢失的数据。在大多数情况下,如果您没有任何备份,您将不走运。
回答by JanL
I'm sorry, bu it's not posible, unless you made a backup file earlier.
对不起,这是不可能的,除非您之前制作了备份文件。
EDIT: Actually it is possible, but it gets very tricky and you shouldn't think about it if data wasn't really, really important. You see: when data get's deleted from a computer it still remains in the same place on the disk, only its sectors are marked as empty. So data remains intact, except if it gets overwritten by new data. There are several programs designed for this purpose and there are companies who specialize in data recovery, though they are rather expensive.
编辑:实际上这是可能的,但它变得非常棘手,如果数据不是真的非常重要,你就不应该考虑它。您会看到:当数据从计算机中删除时,它仍然保留在磁盘上的同一位置,只有其扇区标记为空。因此数据保持完整,除非它被新数据覆盖。有几个为此目的而设计的程序,也有专门从事数据恢复的公司,尽管它们相当昂贵。
回答by Wrikken
For InnoDB tables, Percona has a recovery tool which may help. It is far from fail-safe or perfect, and how fast you stopped your MySQL server after the accidental deletes has a major impact. If you're quick enough, changes are you can recover quite a bit of data, but recovering alldata is nigh impossible.
对于 InnoDB 表,Percona 有一个恢复工具可以帮助. 它远非万无一失或完美无缺,意外删除后您停止 MySQL 服务器的速度会产生重大影响。如果您足够快,则更改可以恢复相当多的数据,但恢复所有数据几乎是不可能的。
Of cours, proper daily backups, binlogs, and possibly a replication slave (which won't help for accidental deletes but does help in case of hardware failure) are the way to go, but this tool could enable you to save as much data as possible when you did not have those yet.
当然,正确的日常备份、二进制日志和可能的复制从属(这不会帮助意外删除,但在硬件故障的情况下会有所帮助)是可行的方法,但此工具可以让您保存尽可能多的数据可能当你没有那些还没有。
回答by Tjekkles
No this is not possible. The only solution will be to have regular backups. This is very important.
不,这是不可能的。唯一的解决方案是定期备份。这是非常重要的。
回答by Piskvor left the building
Unfortunately, no. If you were running the server in default config, go get your backups (you havebackups, right?) - generally, a database doesn't keep previous versions of your data, or a revision of changes: only the current state.
抱歉不行。如果您在默认配置中运行服务器,请获取您的备份(您有备份,对吗?) - 通常,数据库不会保留以前版本的数据或更改的修订版:仅保留当前状态。
(Alternately, if you have deleted the data through a custom frontend, it is quite possible that the frontend doesn't actually issue a DELETE: many tables have a is_deleted
field or similar, and this is simply toggled by the frontend. Note that this is a "soft delete" implemented in the frontend app - the data is not actually deleted in such cases; if you actually issued a DELETE
, TRUNCATE
or a similar SQL command, this is not applicable.)
(或者,如果您通过自定义前端删除了数据,则前端很可能实际上并没有发出 DELETE:许多表都有一个is_deleted
字段或类似的字段,这只是由前端切换。请注意,这是在前端应用程序中实现的“软删除” - 在这种情况下实际上不会删除数据;如果您实际发出了DELETE
,TRUNCATE
或类似的 SQL 命令,这不适用。)
回答by waza123
If you use MyISAMtables, then you can recover any data you deleted, just
如果您使用MyISAM表,那么您可以恢复您删除的任何数据,只需
open file: mysql/data/[your_db]/[your_table].MYD
打开文件:mysql/data/[your_db]/[your_table].MYD
with any text editor
使用任何文本编辑器