How can i rollback my last delete command in mysql?

匿名 (未验证) 提交于 2019-12-03 03:04:01

问题:

I accidentally deleted some huge no. of rows from a table..

How can I roll it back ?

I executed the query using the putty ...

I'll be grateful if any of you can guide me safely out of this..

回答1:

if you haven't made a backup, you are pretty much fudged.



回答2:

If you didn't commit the transaction yet, try rollback. If you have already committed the transaction (by commit or by exiting the command line client), you must restore the data from your last backup.



回答3:

A "rollback" only works if you used transactions. That way you can group queries together and undo all queries if only one of them fails.

But if you already committed the transaction (or used a regular DELETE-query), the only way of getting your data back is to recover it from a previously made backup.



回答4:

use BEGIN TRANSACTION command before starting queries. So that you can ROLLBACK things at any point of time.

FOR EXAMPLE:

  1. begin transaction
  2. select * from Student
  3. delete from Student where Id=2
  4. select * from Student
  5. rollback
  6. select * from Student


回答5:

The accepted answer is not always correct. If you configure binary logging on mysql, you can rollback the database to any previous point you still have a snapshot and binlog for. http://dev.mysql.com/doc/refman/5.0/en/point-in-time-recovery.html is a good starting point for learning about this facility.



回答6:

Rollback normally wont work on this delete functions and surely a backup only can save you. If there is no back up then there is no way to restore it as delete queries ran on putty,derby using .sql files are auto commited once you fire the delete query.



回答7:

If you want rollback data firstly you need to execute autocommit =0 and then execute query delete ,insert or update. After executing the query then execute rollback....



回答8:

i also had deleted some values from my development database, but i had the same copy in QA database , so i did a generate script and selected option "type of data to script" to "data only" and selected my table and then i got the insert statements with same data and then i run the script on my development database.



回答9:

In oracle this would be a non issue

SQL> delete from Employee where id = '01';  1 row deleted.  SQL> select id, last_name from Employee where id = '01';  no rows selected  SQL> rollback;  Rollback complete.  SQL> select * from Employee  where id = '01';  ID   FIRST_NAME LAST_NAME  START_DAT END_DATE      SALARY CITY       DESCRIPTION ---- ---------- ---------- --------- --------- ---------- ---------- --------------- 01   Jason      Martin     25-JUL-96 25-JUL-06    1234.56 Toronto    Programmer 


回答10:

in mysql:

start transaction;

savepoint sp1;

delete from customer where ID=1;

savepoint sp2;

delete from customer where ID=2;

rollback to sp2;

rollback to sp1;



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