Schrödingers MySQL table: exists, yet it does not

后端 未结 11 1876
野趣味
野趣味 2020-11-29 23:47

I am having the weirdest error of all.

Sometimes, when creating or altering tables, I get the \'table already exists\' error. However, DROP TABLE returns \'#1051 - u

11条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 23:56

    It happens at our site (but rarely) usually when an "event" happens while running certain scripts that do a lot of rebuilding. Events include network outages or power problems.
    What I do for this on the very rare occasions it happens - I use the heavy-handed approach:

    • I needed to simply get rid-of-and-rebuild the particular table. I'm usually in a position that this is OK since the table is being built. (Your situation may be different if you need to recover data)
    • As an admin, go into the mysql installation (on windows its may be "...program files/mysql/MySQL Server xx/data/
    • Find the offending file with the table name in the folder - and delete it.
    • Check for orphaned temporary files and delete them too. #...frm files if they happen to be there.
    • MySQL will let you CREATE the table again

    I've had this problem on a couple of different databases over a long time (years). It was a stumper because the contradicting messages. The first time I did a variation of the deleting/rebuilding/renaming database as described in the other answers and managed to get things going, but it definitely takes longer that way. Lucky for me it's always happened to reference tables that are being rebuilt - DROP'd and CREATEd - typically in the morning. Rarely got the problem but came to recognize it as a special quirky case. (I'll restate : if you need to recover the data look to the other solutions.)

    • it isn't a table belonging to another user, or in another database
    • it isn't the upper/lower case issue, I use all lower-case, but that was an interesting issue!
    • it was extra extra frustrating seeing responses with variations of "it definitely was and you're just not doing it right" :)
    • the table didn't show on "show tables"
    • the table was (always was/had been) an INNODB table.
    • trying to DROP the table gave the error message that the table doesn't exist.
    • but trying to CREATE the table gave the error message that the table already exists.
    • using mysql 5.0 or 5.1
    • REPAIR is ineffective for this problem

提交回复
热议问题