MySQL老旧分表设计

该分表是纯物理分表。

create table goods_a(

id int auto_increment,

name varchar(32) not null default '',

price int not null default  0,

pubdate datetime not null default '0000-00-00',

primary key(id)


)  engine  =Myisam charset=utf8;


MySQL老旧分表设计_第1张图片

create table goods_b(

id int auto_increment,

name varchar(32) not null default '',

price int not null default  0,

pubdate datetime not null default '0000-00-00',

primary key(id)

)  engine  =Myisam charset=utf8;


MySQL老旧分表设计_第2张图片

create table goods_c(

id int auto_increment,

name varchar(32) not null default '',

price int not null default  0,

pubdate datetime not null default '0000-00-00',

primary key(id)

)  engine  =Myisam charset=utf8;


MySQL老旧分表设计_第3张图片

create table goods_d(

id int auto_increment,

name varchar(32) not null default '',

price int not null default  0,

pubdate datetime not null default '0000-00-00',

primary key(id)

)  engine  =Myisam charset=utf8;


MySQL老旧分表设计_第4张图片

create table goods_e(

id int auto_increment,

name varchar(32) not null default '',

price int not null default  0,

pubdate datetime not null default '0000-00-00',

primary key(id)

)  engine  =Myisam charset=utf8;


MySQL老旧分表设计_第5张图片

表的物理结构


MySQL老旧分表设计_第6张图片

根据id获得指定一条记录信息

为数据表分区数据的原则就是平均


1)根据id获得指定的一条记录信息

---到指定的分表获得指定的记录信息

$yu=$id%5;

$sql="select*from goods_$yu where id =$id";

2)给指定的分表写入指定的记录信息

$maxId="select max(id)  from goods_fu";

$trueid=$maxId+1;

$yu=$trueid%5;

$sql="insert into goods_$yu values(.....)";

$sql="insert into goods_fu values($trueid)";

思路:获得数据表内部最大主键id值

你可能感兴趣的:(MySQL老旧分表设计)