首页 > 数据库 > > HotDB表信息入门指引
分布式数据库要能正常存储数据,就要知道表如何存储,HotDB当前采用的设计策略是人为指定哪张表以怎么样的规则存储在哪些数据节点中。这里说的人为指定存储方式,指的就是配置表信息,即告诉HotDB该如何存储接下来要创建的对应表。
先在管理平台“配置”》》“表信息”》》“添加表信息”界面,配置即将create的3个表automodtb1、automodtb2、automodtb3分别为以country、id、name作为分片字段的auto_mod自动分片表。按如下方式填写后,点击“生成预览”,“保存”。注意填写说明“表名称与分片字段使用英文冒号间隔,未使用冒号,取默认分片字段”。
#automodtb1以country为分片字段,列散到2个数据节点中
mysql -h192.168.0.250 -P3323 -uroot -proot
use hotdb
drop table if exists automodtb1;
create table automodtb1(id intauto_increment,name varchar(24),country int,primary key(id));
insert into automodtb1(name,country) values(1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1),(9,2),(10,2),(11,2),(12,2),(13,2),(14,2) ,(15,2) ,(16,2) ,(17,3) ,(18,3) ,(19,3) ,(20,3) ,(21,3) ,(22,3) ,(23,3),(24,3);
set show_dnid=1;
select * from automodtb1 order by id;
quit
mysql -h192.168.0.250 -P3323 -uroot -proot
use hotdb
drop table if exists automodtb2;
create table automodtb2(id intauto_increment,name varchar(24),country int,primary key(id));
insert into automodtb2(name,country) values (1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1),(9,2),(10,2),(11,2),(12,2),(13,2),(14,2) ,(15,2) ,(16,2) ,(17,3) ,(18,3) ,(19,3) ,(20,3) ,(21,3) ,(22,3) ,(23,3),(24,3);
set show_dnid=1;
select * from automodtb2 order by id;
quit
mysql -h192.168.0.250 -P3323 -uroot -proot
use hotdb
drop table if exists globaltb1;
create table globaltb1(id int auto_increment,namevarchar(24),country int,primary key(id));
insert into globaltb1(name,country) values(1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1),(9,2),(10,2),(11,2),(12,2),(13,2),(14,2) ,(15,2) ,(16,2) ,(17,3) ,(18,3) ,(19,3) ,(20,3) ,(21,3) ,(22,3) ,(23,3),(24,3);
set show_dnid=1;
select * from globaltb1 order by id;
set merge_result=0;
/!hotdb:dnid=all/select database(), country,count(*)from globaltb1 group by country;
quit
#unconfigtb1以auto_crc32规则,列散到逻辑库hotdb默认的分片节点中
mysql -h192.168.0.250 -P3323 -uroot -proot
use hotdb
drop table if exists unconfigtb1;
create table unconfigtb1(id intauto_increment,name varchar(24),country int,primary key(id));
insert into unconfigtb1(name,country) values(1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1),(9,2),(10,2),(11,2),(12,2),(13,2),(14,2) ,(15,2) ,(16,2) ,(17,3) ,(18,3) ,(19,3) ,(20,3) ,(21,3) ,(22,3) ,(23,3),(24,3);
set show_dnid=1;
select * from unconfigtb1 order by id;
quit
来源 https://www.modb.pro/db/81325
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69999831/viewspace-3128886/ ,如需转载,请注明出处,否则将追究法律责任。