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
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'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.)
I ran into this error after I created a table and deleted it, then wanted to create it again. In my case, I had a self-contained dump file so I dropped my schema, recreated it and imported tables and data using the dump file.
I was having this problem with one particular table. Reading the possible solutions i've did some steps like:
show full tables in database;
: didn't see the problematic one;describe table;
: returned table doesn't exist
;SELECT * FROM information_schema.TABLES WHERE TABLE_NAME='table';
: returned Empty set
;And, after those steps, i check again with the show tables;
and... vualá! the problematic table was gone. I could create it and drop it with the same problematic name with no problem, and i didn't have even to restart the server! Weird...
Going on a wild guess here, but it seems like innodb still has an entry for your tables in a tablespace, probably in ibdata
. If you really don't need any of the data, or if you have backups, try the following:
This is an old question but I just hit the same issue and an answer in one of the related issues linked at the top was just what I needed and far less drastic than deleting files, tables, shutting down the server etc.
mysqladmin -uxxxxxx -pyyyyy flush-tables
I've seen this issue when the data file is missing in the data directory but the table definition file exists or vise-versa. If you're using innodb_file_per_table, check the data directory to make sure you have both an .frm
file and .ibd file for the table in question. If it's MYISAM, there should be a .frm
, .MYI
and a .MYD
file.
The problem can usually be resolved by deleting the orphaned file manually.