mysql提示does n texist_好好的表在MySQL5.6 就Table xxx.xxx dont't exist了

错误提示:Error Code: 1146.

Table mytest.events don't exist.

Please DISCARD the tablespace before IMPORT.

相关原因:

使用hibernate4.2.10 教程时,练习多对多关联,person、person_event、events,这三个表进行关联,建立关联表的 person_event 时候没有在MySQL数据库中设置"外键",对数据库中的表进行HQL : select p from Person p left outer join p.event where p.id=:pid

等操作并进行存取后,成功存取,关闭数据连接,关闭数据库服务,再次打开数据库服务,运行程序,提示Table mytest.events don't exist. 然后打开数据库,在数据库中图形界面点击查询events表,提示相同的错误。

尝试操作:

删除events表,提示Error: table `mytest`.`events` does not exist in the InnoDB internal

data dictionary though MySQL is trying to drop it.

Have you copied the .frm file of the table to the MySQL database

directory from another database?

重启数据库服务后发现表不见了,然后开始建立新表,提示:Cannot create file '.\mytest\events.ibd'

The file '.\mytest\events.ibd' already exists though the

corresponding table did not exist in the InnoDB data dictionary.

Have you moved InnoDB .ibd files around without using the SQL

commands DISCARD TABLESPACE and IMPORT TABLESPACE, or

did mysqld crash in the middle of CREATE TABLE? You can

resolve the problem by removing the file '.\mytest

\events.ibd' under the 'datadir' of MySQL.

网上寻了一些方法[虽然没能解决我的问题,但是知道了一些常用的方法]:

不能建立新表,所以直接找到数据库存数据的地方直接删除相关文件,找到存数据文件的文件夹

D:\MySQL_Data\MySQL_Server5.6\data\mytest\

发现其他表都有*.frm文件,而events没有events.frm,可能是之前在数据库中删除表的时候只删除了这个文件的原因,只剩下events.ibd了,也直接删除。

再次打开数据库,看看数据库里的其他表,发现person_event表也提示相同的错误。

网上提示使用工具MySQL自带的myisamchk ,所以命令行进行如下操作:D:\MySQL\MySQL Server 5.6\bin>myisamchk

-of D:\MySQL_Data\MySQL_Server5.6\data\mytest\person_event.ibd

提示该表不是ISAM表,建立的表默认是InnoDB,所以改用 innochecksum ,

D:\MySQL\MySQL Server 5.6\bin>innochecksum

-v D:\MySQL_Data\MySQL_Server5.6\data\mytest\person_event.ibd

输出 :InnoDB offline file checksum utility.

Variables (--variable-name=value)

and boolean options {FALSE|TRUE} Value (after reading options)

--------------------------------- ----------------------------------------

verbose TRUE

debug FALSE

count FALSE

start-page 0

end-page 0

page 0

file D:\MySQL_Data\MySQL_Server5.6\data\mytest\person_event.ibd = 1146

88 bytes (7 pages)...

InnoChecksum; checking pages in range 0 to 6

Fail; page 0 invalid (fails old style checksum)

继续执行:mysqlcheckD:\MySQL\MySQL Server 5.6\bin>mysqlcheck -a -u root -p mytest

Enter password: ****

mytest.person OK

mytest.person_email_addr OK

mytest.person_event

Error : Table 'mytest.person_event' doesn't exist

status : Operation failed

mytest.sys_user OK

不管用......

解决方法:

经过了上面的尝试和网上方法的提示,忽然想到查看一下数据库的错误日志,

于是找到到存数据的目录:D:\MySQL_Data\MySQL_Server5.6\data

在这里找到了错误日志文件:PCNAME-yymmddHHMM.err

里面罗列了好多内容,其中一些是这样写的:

2014-03-21 23:46:54 100300 [Warning] InnoDB:

Load table 'mytest/person_event' failed,

the table has missing foreign key indexes.

Turn off 'foreign_key_checks' and try again.

2014-03-21 23:46:54 100300 [Warning] InnoDB:

Cannot open table mytest/person_event from the internal

data dictionary of InnoDB though the .frm file for the table exists.

See http://dev.mysql.com/doc/refman/5.6/en/innodb-

troubleshooting.html for how you can resolve the problem.

上网查询了一下关闭'foreign_key_checks'的方法:禁用外码约束

SET FOREIGN_KEY_CHECKS=0;

启动外码约束

SET FOREIGN_KEY_CHECKS=1;

查看当前FOREIGN_KEY_CHECKS的值可用如下命令

SELECT @@FOREIGN_KEY_CHECKS;

于是打开数据库,执行语句SET FOREIGN_KEY_CHECKS=0;

再次打开表person_event,可以正常查询了!然后打开表的FOREIGN KEYS附加选项,将里面的内容删除“FK_7bh2i9xjn8v93x5ku5w61npwf”。

总结:

看错误日志文件,里面的提示最能提示我问题出在哪里了,确定问题再查!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值