How can I roll back my last delete command in MySQL?

后端 未结 10 2027
臣服心动
臣服心动 2020-12-25 09:32

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

How can I roll it back?

I executed the query using PuTTY.

I\'ll be grateful if any of

相关标签:
10条回答
  • 2020-12-25 10:27

    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
    
    0 讨论(0)
  • 2020-12-25 10:31

    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;
    
    0 讨论(0)
  • 2020-12-25 10:32

    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.

    7.5 Point-in-Time (Incremental) Recovery Using the Binary Log is a good starting point for learning about this facility.

    0 讨论(0)
  • 2020-12-25 10:35

    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.

    0 讨论(0)
提交回复
热议问题