I was trying to do an update on the MySQL server and accidentally forgot to add an additional WHERE clause which was supposed to edit one row.
I now have 3500+ rows edited due to my error.
I may have a back up but I did a ton of work since the last backup and I just dont want to waste it all because of 1 bad query.
Please tell me there is something i can do to fix this.
MySQL Rollback statement allows you to rollback or undo one more statements that have been recently executed. For example, if you have accidentally deleted or updated rows, you can use MySQL rollback those statements and restore original databases.
To have possibility to ROLLBACK DML statements (like INSERT , UPDATE or DELETE queries) you should use transaction blocks: START TRANSACTION; UPDATE CUSTOMERS SET ADDRESS = 'Pune' WHERE ID = 6; -- and more DML queries COMMIT; -- or ROLLBACK; Since transaction was COMMIT ed it can not be rolled back.
Basically: If you're doing a transaction just do a rollback. Otherwise, you can't "undo" a MySQL query. Show activity on this post. For some instrutions, like ALTER TABLE, this is not possible with MySQL, even with transactions (1 and 2).
Undo is called rollback in SQL. Once you've done a commit , you can't undo it without getting into restoring backups. Note that doing a rollback will undo an entire transaction, which means every update, insert, and delete since the transaction began, which is usually since the last commit or rollback.
If you committed your transaction, it's time to dust off that backup, sorry. But that's what backups are for. I did something like that once myself... once.
Just an idea - could you restore your backup to a NEW database and then do a cross database query to update that column based on the data it used to be?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With