Schrödinger’s Mysql table – does it exist?

Recently I ran in to a particularly odd database problem – a mysql table that both existed and didn’t at the same time. Queries were failing, reporting that the table didn’t exist. Yet when I tried to recreate this Schrödinger’s table, mysql insisted that it already existed, and wouldn’t recreate it.

So what gives?

The error

When trying to query the table, the console returned the following:

mysql> SELECT * FROM mytable;
ERROR 1051 (42S02): Table 'mytable' already exists

mysql> DROP TABLE mytable;
ERROR 1051 (42S02): Unknown table 'mytable'

The mysql error log was a bit more verbose:

140221  8:28:03  InnoDB: Error: table `mydatabase/mytable` does not exist in the InnoDB internal
InnoDB: data dictionary though MySQL is trying to drop it.
InnoDB: Have you copied the .frm file of the table to the
InnoDB: MySQL database directory from another database?
InnoDB: You can look for further help from
InnoDB: http://dev.mysql.com/doc/refman/5.0/en/innodb-troubleshooting.html

The Solution

Digging in to it a bit more, it appeared that this database had it’s data dictionary copied from elsewhere. Apparently with InnoDB tables in particular, there’s a risk of InnoDB’s own copy of the data dictionary getting out of sync with that kept by mysql in .frm files.

This appears to be what happened in this case – at some point, corruption took place, leaving an orphaned data file existing in the data dictionary, but the table definition file was missing.

After going to the data directory and deleting the “.frm” file for the table concerned, order was restored, and the table could be recreated without issue.

Share This Article

Related Articles


Creating favicons from emojis and SVGs

While bundling up a recent side project for launch, I had to generate favicons for the project. A simple side project, the favicon was basically just an emoji. Rather than generating a bunch of png and ico files, could I just use the emoji directly?

Creating Animated Gifs from MP4 and WebM files using ffmpeg

Efficient video encoding has meant that sharing mp4/webm files has become more widespread. However for tools that don't readily support video playback (Google Slides..), it's sometimes still necessary to use gifs. Happily, ffmpeg makes this very easy!

Persistent WiFi failure on Ubuntu 24.04

Updates to Ubuntu 24.04 led to regular loss of wifi connection, often requiring a hard reboot. As ever with Ubuntu, there are about 3,928 possible solutions to any given problem. Here's the path which ultimately worked for me!

More