问题
I have a very interesting case. Several of my InnoDB tables got somehow corrupted. The .frm files of the tables disappeared and only the .ibd files were left.
I thought no problem, I will restore these tables from the backup, so I deleted the .frm files and try to create the new tables with the same name, but every time I get "the table already exists", the .ibd file gets created, but the .frm not.
Basically now I cannot create InnoDB tables with the given names in the given database. My only solution was to create MyISAM tables instead, but I would still like to know how to resolve this.
Below is a detailed log of the events:
- Try to create the table:
CREATE TABLE
employee
(employee_id
varchar(20) NOT NULL,
PRIMARY KEY (employee_login_id
) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 PACK_KEYS=1 ROW_FORMAT=COMPRESSED
table already exists
- Try to drop the table to show that it doesn't exist:
DROP TABLE employee
table doesn't exist
I manually deleted the employee.ibd file (there is no employee.frm file)
Try #1 again and receive the "table already exists" again
I have restarted MySQL, no change. I have restarted the whole server, no change.
I cannot create an InnoDB table with the name "employee" in this tablespace anymore.
Any idea?
回答1:
Information about a table is stored in two places:
- Server-wide table.frm file
- Storage-engine specific InnoDB dictionary
These two must be in-sync, but there is no reliable mechanism to enforce this consistency. Due to number of reasons InnoDB dictionary gets out of sync.
In your case there is an orphaned record in the dictionary. You need to delete it.
InnoDB doesn't provide any way to manually modify the dictionary records. But you can craft a fake table.frm (if innodb_file_per_table=ON then table.ibd too) files, put it into the database directory and drop the table.
Old versions of InnoDB might complain about mismatching SPACENO. Then check how to fix InnoDB dictionary
来源:https://stackoverflow.com/questions/28238942/mysql-5-6-10-innodb-cannot-create-table-as-table-already-exists