Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to undo a query execution in phpmyadmin

Tags:

php

mysql

How to undo a query execution in phpmyadmin.

Any rollback functionality is there? any body knows the solution kindly help me?

like image 671
DEVOPS Avatar asked Jan 29 '11 10:01

DEVOPS


People also ask

How do I stop MySQL query execution?

Run the following command: mysql> SELECT GROUP_CONCAT(CONCAT('KILL ',id,';') SEPARATOR ' ') FROM information_schema. processlist WHERE user <> 'system user'; This will kill all your MySQL queries.

How do you undo a SQL query?

The ROLLBACK command is the transactional command used to undo transactions that have not already been saved to the database. This command can only be used to undo transactions since the last COMMIT or ROLLBACK command was issued.

Is there an undo command in MySQL?

Undo logs exist within undo log segments, which are contained within rollback segments. Rollback segments reside in the system tablespace, in undo tablespaces, and in the temporary tablespace. Undo logs that reside in the temporary tablespace are used for transactions that modify data in user-defined temporary tables.


1 Answers

If the statement is still running you can use KILL QUERY <thread_id>.

If the statement has completed but you have not yet committed the transaction you can use ROLLBACK.

If the statement has completed and the transaction is already committed (or you didn't start a transaction) then restore the data from your most recent backup.


Also here are some tips advice in order to prevent this type of situation happening in the first place:

  • When writing a DELETE or UPDATE always write the WHERE clause first so that you don't forget it.
  • Test your WHERE clause in a SELECT statement to make sure you are updating the correct rows.
  • If you know you should only be updating one row then you can add LIMIT 1 to your UPDATE statement. Then if despite using the above techniques you still have an error at least only one row will be affected, not the entire database.
like image 103
Mark Byers Avatar answered Sep 20 '22 16:09

Mark Byers