mysql 分表 merge_mysql 分表 --- merge

粗略方式 之 merge 分表法

-- 分表设计

DROP table IF EXISTS tb_schtest1;

create table tb_schtest1(

id bigint primary key auto_increment ,

`name` varchar(20),

sex tinyint not null default '0'

)ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

DROP table IF EXISTS tb_schtest2;

create table tb_schtest2(

id bigint primary key auto_increment ,

`name` varchar(20),

sex tinyint not null default '0'

)ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

DROP table IF EXISTS tb_schtest3;

create table tb_schtest3(

id bigint primary key auto_increment ,

`name` varchar(20),

sex tinyint not null default '0'

)ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

DROP table IF EXISTS tb_schtest4;

create table tb_schtest4(

id bigint primary key auto_increment ,

`name` varchar(20),

sex tinyint not null default '0'

)ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

DROP table IF EXISTS tb_schtest5;

create table tb_schtest5(

id bigint primary key auto_increment ,

`name` varchar(20),

sex tinyint not null default '0'

)ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

DROP table IF EXISTS tb_schtest10;

create table tb_schtest10(

id bigint primary key auto_increment ,

`name` varchar(20),

sex tinyint not null default '0'

)ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

DROP table IF EXISTS tb_schtest6;

create table tb_schtest6(

id bigint primary key auto_increment ,

`name` varchar(20),

sex tinyint not null default '0'

)ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

DROP table IF EXISTS tb_schtest7;

create table tb_schtest7(

id bigint primary key auto_increment ,

`name` varchar(20),

sex tinyint not null default '0'

)ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

DROP table IF EXISTS tb_schtest8;

create table tb_schtest8(

id bigint primary key auto_increment ,

`name` varchar(20),

sex tinyint not null default '0'

)ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

DROP table IF EXISTS tb_schtest9;

create table tb_schtest9(

id bigint primary key auto_increment ,

`name` varchar(20),

sex tinyint not null default '0'

)ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

-- merge 总表

DROP table IF EXISTS tb_schtest;

create table tb_schtest(

id bigint primary key auto_increment ,

`name` varchar(20),

sex tinyint not null default '0'

)ENGINE=MERGE UNION=(tb_schtest1,tb_schtest2,tb_schtest3,tb_schtest4,tb_schtest5,tb_schtest6,tb_schtest7,tb_schtest8,tb_schtest9,tb_schtest10) INSERT_METHOD=LAST CHARSET=utf8 AUTO_INCREMENT=1 ;

-- 数据处理

insert into tb_schtest1(id,`name`,sex) select id,`name`,sex from schtest where id%10=0;

insert into tb_schtest2(id,`name`,sex) select id,`name`,sex from schtest where id%10=1;

insert into tb_schtest3(id,`name`,sex) select id,`name`,sex from schtest where id%10=2;

insert into tb_schtest4(id,`name`,sex) select id,`name`,sex from schtest where id%10=3;

insert into tb_schtest5(id,`name`,sex) select id,`name`,sex from schtest where id%10=4;

insert into tb_schtest6(id,`name`,sex) select id,`name`,sex from schtest where id%10=5;

insert into tb_schtest7(id,`name`,sex) select id,`name`,sex from schtest where id%10=6;

insert into tb_schtest8(id,`name`,sex) select id,`name`,sex from schtest where id%10=7;

insert into tb_schtest9(id,`name`,sex) select id,`name`,sex from schtest where id%10=8;

insert into tb_schtest10(id,`name`,sex) select id,`name`,sex from schtest where id%10=9;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值