直接根据数据量进行拆分
有一个5000条数据的表,要把它变成没1000条数据一个表的5等份。
假设:表名:xuesi 主键:kid
xuesi共有5000条数据,kid从1到5000自动增长
题目:将xuesi分成5个表 每个表1000条不同的数据
方法1:
create table xuesi1 select * from xuesi order by kid limit 0,1000;
create table xuesi2 select * from xuesi order by kid limit 1000,1000;
create table xuesi3 select * from xuesi order by kid limit 2000,1000;
create table xuesi4 select * from xuesi order by kid limit 3000,1000;
create table xuesi4 select * from xuesi order by kid limit 4000,1000;
以上方法 是根据大表xuesi的主键kid 创建了xuesi1,xuesi2,xuesi3,xuesi4,xuesi5 五等份的小表
不足:primary key 属性丢失
方法2:
create table xuesi1 like xuesi;
insert into xuesi1 select * from xuesi order by limit 0,1000;
create table xuesi2 like xuesi;
insert into xuesi2 select * from xuesi order by limit 1000,1000;
create table xuesi2 like xuesi;
insert into xuesi3 select * from xuesi order by limit 2000,1000;
create table xuesi3 like xuesi;
insert into xuesi4 select * from xuesi order by limit 3000,1000;
create table xuesi5 like xuesi;
insert into xuesi5 select * from xuesi order by limit 4000,1000;