1、水平分表
创建结构相同的N个表
create table student_0 (
id int not null auto_increment,name varchar(12),primary key (id)
);
create table student_1 (
id int not null auto_increment,primary key (id)
);
create table student_2 (
id int not null auto_increment,primary key (id)
);
create table student_id (
id int not null auto_increment,primary key (id)
);
//伪代码
$tableList = array(
'student_0','student_1','student_2'
);
$tableNums = count($tableList);
$sqlId = "insert into student_id values(null)";
$stuId = last_insert_id();
$tableName = $tableList[$stuId % $tableNums];
$sql = "insert into {$tableName} values({$stuId},'测试')";
2、merge,mrg_myisam存储引擎
MysqL提供一个可以将多个结构相同的myisam表,合并到一起的存储引擎。
3、垂直分表
表中存在多个字段,将常用字段和非常用字段分别存到两张或以上的表中,
主要目的,减少每条记录的长度。
比如学生表:
基础信息表student_base
额外信息表student_extra
基础表与额外表之间通过ID来对应。
(*水平分表现在用MysqL自带的partition已经很好解决了)