How can I undo a mysql statement that I just executed?
If you define table type as InnoDB, you can use transactions. 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.
ROLLBACK -- will undo the changes that you have made
You can only do so during a transaction.
BEGIN;
INSERT INTO xxx ...;
DELETE FROM ...;
Then you can either:
COMMIT; -- will confirm your changes
Or
ROLLBACK -- will undo your previous changes
Basically: If you're doing a transaction just do a rollback. Otherwise, you can't "undo" a MySQL query.