使用Merge存储引擎实现MySQL分表
学习了:https://www.cnblogs.com/try-better-tomorrow/p/4987620.html
https://www.cnblogs.com/xbq8080/p/6628034.html
http://blog.csdn.net/java_bruce/article/details/71077985
https://www.cnblogs.com/johnnyzhang/articles/2648669.html
注意啊,使用Merge的时候,只能集合MyISAM性质的表;
mysql> show enginesG *************************** 2. row *************************** Engine: MRG_MYISAM Support: YES Comment: Collection of identical MyISAM tables Transactions: NO XA: NO Savepoints: NO *************************** 3. row *************************** Engine: MyISAM Support: YES Comment: MyISAM storage engine Transactions: NO XA: NO Savepoints: NO
使用show engines的时候可以看到,MRG_MYISAM就是为MyISAM准备的;
创建脚本如下:
CREATE TABLE t1 ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, message CHAR(20))ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; CREATE TABLE t2 ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, message CHAR(20))ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; CREATE TABLE total ( id INT NOT NULL AUTO_INCREMENT, message CHAR(20), INDEX(id)) ENGINE=MERGE UNION=(t1,t2) INSERT_METHOD=LAST;
就是说,用InnoDB引擎创建的表不能进行Merge聚合;