Home » Mysql » How can i rollback my last delete command in mysql?

How can i rollback my last delete command in mysql?

Posted by: admin November 1, 2017 Leave a comment

Questions:

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

Answers:

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

Questions:
Answers:

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.

Questions:
Answers:

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.

Questions:
Answers:

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.

Questions:
Answers:

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
Questions:
Answers:

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.

Questions:
Answers:

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

Questions:
Answers:

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.