mysql Cannot find or open table x/x 及解决办法

来源:互联网 发布:淘宝数据魔方在哪里 编辑:程序博客网 时间:2024/06/07 04:09

今天修改mysql配置,重构后,进入数据库能show tables查看到表,却无法select表,出现

Table x doesn't exist

的报错,查看mysql错误日志:

[ERROR] Cannot find or open table x/x from

the internal data dictionary of InnoDBthough the .frm file for the

table exists. Maybe you have deleted andrecreated InnoDB data

files but have forgotten to delete thecorresponding .frm files

of InnoDB tables, or you have moved .frmfiles to another database?

or, the table contains indexes that thisversion of the engine

doesn't support.


show engines;

查看到


没发现异常。

后来查到是ibdata1中的data dictionary和information schema中的不一致导致的

ibdata1中的data dictionary:

mysql默认会将所有的数据库InnoDB引擎的表数据存储在一个共享空间中:ibdata1

Innodb共享表空间文件ibdata1中存储了以下几部分信息:

1.Data dictonary

2.Double write buffer

3.Insert buffer

4.Rollback segments

5.UNDO space

因此,我们在初始化ibdata1时,最好设置大一些,这样就可以避免因为在高并发情景下导致ibdata1急剧增大,大大影响性能。

 information schema:

information_schema数据库是MySQL自带的,它提供了访问数据库元数据的方式。什么是元数据呢?元数据是关于数据的数据,如数据库名或表名,列的数据类型,或访问权限等。有些时候用于表述该信息的其他术语包括“数据词典”和“系统目录”。

在MySQL中,把 information_schema 看作是一个数据库,确切说是信息数据库。其中保存着关于MySQL服务器所维护的所有其他数据库的信息。如数据库名,数据库的表,表栏的数据类型与访问权 限等。在INFORMATION_SCHEMA中,有数个只读表。它们实际上是视图,而不是基本表,因此,你将无法看到与之相关的任何文件。


那么如何修复呢?我也没找到特别好的办法,只能通过ibd文件进行数据恢复:

http://blog.csdn.net/xiangliangyu2008/article/details/8450812


结论:

如果直接拷贝原有数据库文件"*.frm"、"*.MYD"、"*.MYI"等文件时候,如果原数据库引擎是InnoDB,切记还需拷贝ibdata1文件


转载请注明文章转自:良玉的博客 [http://blog.uouo123.com]

原创粉丝点击