加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

mysql分表

发布时间:2020-12-11 23:16:49 所属栏目:MySql教程 来源:网络整理
导读: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 aut
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已经很好解决了)

?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读