个人技术空间

解决MySQL创建表时候提示存在

在创建表的时候提示

Table 'xxx' already exists

删除这个表的时候又提示不存在。

同时在mysql的日志重看到了这样的日志

2018-11-08 22:05:56 18372 [ERROR] InnoDB: Table xxx/xxx in the InnoDB data dictionary has tablespace id 1048, but tablespace with that id or name does not exist. Have you deleted or moved .ibd files? This may also be a table created with CREATE TEMPORARY TABLE whose .ibd and .frm files MySQL automatically removed, but the table still exists in the InnoDB internal data dictionary.

这种一般是在innodb_file_per_table启用的情况下会出现的
解决方法如下:

  1. 去别的数据库中创建一个一摸一样的表
  2. 将这个表的frm文件拷贝到有问题数据库的目录下
  3. 执行drop table
  4. 再执行create table就成功了

参考文章:https://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html

版权声明:署名-非商业性使用-禁止演绎 3.0 未本地化版本 (CC BY-NC-ND 3.0)