今天把数据库从5.0的一个mysql版本迁移到mysql 5.1的过程中遇到一个问题,发现一个MERGE表一直出现Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist报错,但是在5.0上一直是OK的,于是进行了一些实践后发现是由于MERGE的表索引和其他子表不一致导致。
添加索引之后正常了。而为什么5.0是正常的呢,我猜测是由于5.0的版本对MERGE表没有那么严格的要求。
因此当遇到Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist报错的时候需要从如下几个方面入手:
1、查看是不是有一些表不是MYISAM引擎的表,因为MERGE引擎只适用于MYISAM表
2、查看是不是在union的表中含有不存在的表。
3、查看是不是MERGE的时候引用了不在同一个库的表,并且该表没有指定数据库名字。
4、比较各个表的结构(索引、引擎、列、字符集等)是否一致。

子表代码为:

CREATE TABLE `test0` (
  `uin` int(10) unsigned NOT NULL,
  `data` text NOT NULL,
  `modtime` int(10) unsigned NOT NULL,
  PRIMARY KEY (`uin`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `test1` (
  `uin` int(10) unsigned NOT NULL,
  `data` text NOT NULL,
  `modtime` int(10) unsigned NOT NULL,
  PRIMARY KEY (`uin`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `test2` (
  `uin` int(10) unsigned NOT NULL,
  `data` text NOT NULL,
  `modtime` int(10) unsigned NOT NULL,
  PRIMARY KEY (`uin`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `test3` (
  `uin` int(10) unsigned NOT NULL,
  `data` text NOT NULL,
  `modtime` int(10) unsigned NOT NULL,
  PRIMARY KEY (`uin`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `test4` (
  `uin` int(10) unsigned NOT NULL,
  `data` text NOT NULL,
  `modtime` int(10) unsigned NOT NULL,
  PRIMARY KEY (`uin`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `test5` (
  `uin` int(10) unsigned NOT NULL,
  `data` text NOT NULL,
  `modtime` int(10) unsigned NOT NULL,
  PRIMARY KEY (`uin`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `test6` (
  `uin` int(10) unsigned NOT NULL,
  `data` text NOT NULL,
  `modtime` int(10) unsigned NOT NULL,
  PRIMARY KEY (`uin`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `test7` (
  `uin` int(10) unsigned NOT NULL,
  `data` text NOT NULL,
  `modtime` int(10) unsigned NOT NULL,
  PRIMARY KEY (`uin`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `test8` (
  `uin` int(10) unsigned NOT NULL,
  `data` text NOT NULL,
  `modtime` int(10) unsigned NOT NULL,
  PRIMARY KEY (`uin`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `test9` (
  `uin` int(10) unsigned NOT NULL,
  `data` text NOT NULL,
  `modtime` int(10) unsigned NOT NULL,
  PRIMARY KEY (`uin`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

 

 

MERGE表代码为:

 

CREATE TABLE `test` (
  `uin` int(10) unsigned NOT NULL,
  `data` text NOT NULL,
  `modtime` int(10) unsigned NOT NULL,
  PRIMARY KEY  (`uin`),
  KEY `modtime` (`modtime`)
) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 UNION=(`test0`,`test1`,`test2`,`test3`,`test4`,`test5`,`test6`,`test7`,`test8`,`test9`);

 

相关文章:

  • 2021-11-18
  • 2021-06-17
  • 2021-06-10
  • 2021-11-24
  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
  • 2022-03-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
  • 2021-09-15
  • 2022-03-04
  • 2021-07-25
  • 2021-06-30
相关资源
相似解决方案