Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to rollback after commit in MySQL?

Tags:

I did a big mistake that I updated a table without 'where' clause in MySQL :'(

It is auto-committed.

Is there any way to rollback from it?

like image 470
Johnny Lim Avatar asked Dec 24 '12 02:12

Johnny Lim


People also ask

Can rollback be done after commit?

After you commit the transaction, the changes are visible to other users' statements that execute after the commit. You can roll back (undo) any changes made during the transaction with the ROLLBACK statement (see ROLLBACK.

How do I rollback a MySQL transaction?

To roll back the current transaction and cancel its changes, you use the ROLLBACK statement. To disable or enable the auto-commit mode for the current transaction, you use the SET autocommit statement.

Can we rollback committed transaction in SQL?

Once SQL Server commits a transaction, you cannot run the ROLLBACK statement.

Can we rollback without commit?

On ending the transaction without specifying committing or rolling back, it will roll back. So, the advice given below is definitely correct: always explicitly commit or rollback.


1 Answers

No, there's no query that will "undo" a committed data-modifying query.

If you have a backup of the database, you can restore the backup and use DBA tools (in MySQL's case, it's mysqlbinlog) to "replay" all data-modifying queries from the logs since the backup back to the database, but skip over the problem query.

If you don't have a backup and all logs since the that backup, there's nothing you can do to recover the data.

like image 68
Bohemian Avatar answered Oct 15 '22 03:10

Bohemian