一、利用merge存储引擎来实现分表
1、创建分表,和主表的表结构相同,这里创建3个表
2、复制主表数据到分表
这样插入新的数据会插入的cpthack3,最后一个表中
----------------------------------------------------------------------------------------------------------
以下是测试实例:
将代码copy之后保存为xxx.sql文件即可
/*
Navicat MySQL Data Transfer
Source Server : localhost
Source Server Version : 50045
Source Host : localhost:3306
Source Database : cpt1
Target Server Type : MYSQL
Target Server Version : 50045
File Encoding : 65001
Date: 2014-05-09 16:34:21
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `user`
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(50) default NULL,
`description` varchar(20) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('2', 'cpthack', '12312312312312312312');
-- ----------------------------
-- Table structure for `user1`
-- ----------------------------
DROP TABLE IF EXISTS `user1`;
CREATE TABLE `user1` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(50) default NULL,
`description` varchar(20) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=459 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of user1
-- ----------------------------
INSERT INTO `user1` VALUES ('100', '123', '13123');
INSERT INTO `user1` VALUES ('101', 'test', '成佩涛测试的数据');
INSERT INTO `user1` VALUES ('102', 'test', '成佩涛测试的数据');
INSERT INTO `user1` VALUES ('103', 'test', '成佩涛测试的数据');
INSERT INTO `user1` VALUES ('104', 'test', '成佩涛测试的数据');
INSERT INTO `user1` VALUES ('105', 'test', '成佩涛测试的数据');
INSERT INTO `user1` VALUES ('106', 'test', '成佩涛测试的数据');
INSERT INTO `user1` VALUES ('107', 'test', '成佩涛测试的数据');
-- ----------------------------
-- Table structure for `userall`
-- ----------------------------
DROP TABLE IF EXISTS `userall`;
CREATE TABLE `userall` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(50) default NULL,
`description` varchar(20) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MRG_MyISAM DEFAULT CHARSET=utf8 INSERT_METHOD=LAST UNION=(`user`,`user1`);
-- ----------------------------
-- Records of userall
-- ----------------------------
INSERT INTO `userall` VALUES ('2', 'cpthack', '12312312312312312312');
INSERT INTO `userall` VALUES ('100', '123', '13123');
INSERT INTO `userall` VALUES ('101', 'test', '成佩涛测试的数据');
INSERT INTO `userall` VALUES ('102', 'test', '成佩涛测试的数据');
INSERT INTO `userall` VALUES ('252', 'test', '成佩涛测试的数据');
INSERT INTO `userall` VALUES ('253', 'test', '成佩涛测试的数据');
INSERT INTO `userall` VALUES ('254', 'test', '成佩涛测试的数据');
INSERT INTO `userall` VALUES ('255', 'test', '成佩涛测试的数据');
INSERT INTO `userall` VALUES ('256', 'test', '成佩涛测试的数据');
INSERT INTO `userall` VALUES ('257', 'test', '成佩涛测试的数据');
PS:本文关键词 :mysql分表 mysql merge分表