How do I repair an InnoDB table?

后端 未结 7 1098
迷失自我
迷失自我 2020-11-30 02:52

We (apparently) had poorly executed of our Solaris MySQL database engine last night. At least some of the InnoDB tables are corrupted, with timestamp out of order errors in

7条回答
  •  忘掉有多难
    2020-11-30 03:34

    The following solution was inspired by Sandro's tip above.

    Warning: while it worked for me, but I cannot tell if it will work for you.

    My problem was the following: reading some specific rows from a table (let's call this table broken) would crash MySQL. Even SELECT COUNT(*) FROM broken would kill it. I hope you have a PRIMARY KEY on this table (in the following sample, it's id).

    1. Make sure you have a backup or snapshot of the broken MySQL server (just in case you want to go back to step 1 and try something else!)
    2. CREATE TABLE broken_repair LIKE broken;
    3. INSERT broken_repair SELECT * FROM broken WHERE id NOT IN (SELECT id FROM broken_repair) LIMIT 1;
    4. Repeat step 3 until it crashes the DB (you can use LIMIT 100000 and then use lower values, until using LIMIT 1 crashes the DB).
    5. See if you have everything (you can compare SELECT MAX(id) FROM broken with the number of rows in broken_repair).
    6. At this point, I apparently had all my rows (except those which were probably savagely truncated by InnoDB). If you miss some rows, you could try adding an OFFSET to the LIMIT.

    Good luck!

提交回复
热议问题