Forum Moderators: coopster

Message Too Old, No Replies

How can I undo an update I did in MYSQL

UNDO Update

         

Drunk N Japan

4:10 pm on Jun 27, 2007 (gmt 0)

10+ Year Member



I have committed a grave error and I can't seem to find any way to fix it. I performed an update on our database without realizing that Mysql is not case sensitive. This update in turn affected many many rows that should have been left alone. I have been searching frantically for a way to UNDO the Update but I can not find any thing that clearly tells me how to do this. I know that there are logs created for each transaction but I need to fix this before to many other changes are done to the database.

jatar_k

4:13 pm on Jun 27, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



that's called a rollback, not sure if you have that option but you can look through these

[mysql.com...]

the other option is to restore from the most recent backup

Drunk N Japan

4:19 pm on Jun 27, 2007 (gmt 0)

10+ Year Member



Can I use rollback from phpmyadmin if I did not create a save point?

jatar_k

4:22 pm on Jun 27, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



not really sure but I don't think so

laidbackwebsage

7:42 am on Jun 28, 2007 (gmt 0)

10+ Year Member



If you have access to the actual MySql logs, you can do the following:

1) Create an empty copy of the table with a new table name.
2) Use your favorite method to pull out all the SQL INSERT, UPDATE and DELETE statements for the original table and put them in their own file. (I wrote a Perl script for this myself; regular expressions are your friend.)
3) Remove the bad statement(s) from your new SQL file.
4) Change the original table name to the copy's table name.
5) Run your SQL file:

mysql -p -u <username> < file.sql

6) Rename your original table:
RENAME TABLE original TO original_bad;

7) Rename your copy table with the restored data to the original table:
RENAME TABLE copy TO original;

Should be good to go after that...