tags:

views:

163

answers:

4

How can I undo the most recently executed mysql query?

+7  A: 

Basically: If you're doing a transaction just do a rollback. Otherwise, you can't "undo" a MySQL query.

halfdan
MySQL doc about transactions: http://dev.mysql.com/doc/refman/5.0/en/commit.html
Unkwntech
Let's hope you have logs and backups...
Konerak
+1  A: 

You can only do so during a transaction.

BEGIN;
INSERT INTO xxx ...;
DELETE FROM ...;

Then you can either:

COMMIT; -- will confitm your changes

Or

ROLLBACK -- will undo
Palantir
+1  A: 

If you define table type as InnoDB, you can use transactions (see the link below). You will need set AUTOCOMMIT=0, and after you can issue COMMIT or ROLLBACK at the end of query or session to submit or cancel a transaction.

http://dev.mysql.com/doc/mysql/en/InnoDB_transaction_model.html

ROLLBACK -- will undo the changes that you have made
Vimard
+1  A: 

You can stop a query which is being processed by this

Find the Id of the query process by => show processlist;

Then => kill id;

RINSON KE