Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If I kill a delete query in mysql, will the rows all be saved?

Suppose I'm halfway through running an import, and instead of running

SELECT COUNT(*) FROM table_being_imported

I hit ctrl+R, type table_being_im and hit return, only to find to my horror that I've just issued

DELETE FROM table_being_imported

Oops. So I hit ctrl+C and get told:

Ctrl-C -- sending "KILL QUERY 627" to server ...
Ctrl-C -- query aborted.
ERROR 1317 (70100): Query execution was interrupted

Would it have deleted any of the rows? Just hypothetically, of course...

like image 323
Simon Avatar asked Dec 01 '10 13:12

Simon


People also ask

What does delete query return?

The standard DELETE statement in SQL returns the number of deleted rows.

How do I recover a deleted record in MySQL?

Once the row is deleted it is gone. You can will have to use a backup to restore the data. The exceptions to this are if you are doing a delete inside an open Transaction, in those cases you can "Rollback" the transaction to undo any changes made inside the transaction.

What will happen if you execute delete?

If you run a DELETE statement with no conditions in the WHERE clause, all of the records from the table will be deleted.


1 Answers

hypothetically,... some of those rows are now gone.

During UPDATE or DELETE operations, the kill flag is checked after each block read and after each updated or deleted row. If the kill flag is set, the statement is aborted. Note that if you are not using transactions, the changes are not rolled back.

Not that this is the time to mention it, but this is why Transactional queries are best when dealing with business-critical data.

like image 151
FatherStorm Avatar answered Dec 08 '22 01:12

FatherStorm