Filing Away for Future Use: MySQL Stupidity
12 Oct 2007We had a database issue the other day. We were losing records in our DNS database. It turned out the table was corrupt and inserts were failing.
We used MySQL's REPLACE INTO to update the table. So, in essence, this is what was happening:
try to insert domain
oh, I can't insert? that means it's already there
delete the existing record
try to insert again
On a happy table, that works just fine. The INSERT fails initially because the table is corrupt, but REPLACE INTO thinks it is because the record exists. So it DELETEs it. Then it tries to futilely INSERT the replacement record, which obviously fails.
Now we're down one record. Oops.
Thankfully, it was easy for us to fix the table and replay the changes and get everything back to normal. Yay. Filing this one away in my brain in case I run into it again.