赞
踩
说明
本文将不再使用 Mycat 的序列功能,因为该功能过于鸡肋,实现度低,难用问题多。
不分库只分表,分片键为 id。
逻辑表名为 not_db_tb
。
分片 ID | 分片键 | 物理实例(存储节点) | 物理库 | 物理表 | 描述 |
---|---|---|---|---|---|
0 | id | rep01Src | sharding | not_db_tb_0 | id 双数 |
1 | id | rep01Src | sharding | not_db_tb_1 | id 单数 |
注释
MOD_HASH()
其实是对id
散列化后的散列值取模,在本例中即单双。本文仅为简化说明,实则所有id 单/双数
、id%10
等均表示此意。
# drop old table, and delete old data record drop table if exists not_db_tb; # create table /*+ mycat:createTable{ "schemaName":"sharding", "shardingTable":{ "createTableSQL":"create table not_db_tb(id int primary key,name varchar(10),city varchar(10)) tbpartition by MOD_HASH(id) tbpartitions 2", "function":{ "properties":{ "dbNum":1, "tableNum":2, "tableMethod":"mod_hash(id)", "mappingFormat":"cls0/sharding/not_db_tb_${tableIndex}", "storeNum":2 } } }, "tableName":"not_db_tb" } */; # insert data insert into not_db_tb(id,name,city) values(1,'a','sh'),(2,'b','sh'),(3,'c','bj'),(4,'d','sh'),(5,'e','sz'),(6,'f','bj'),(7,'g','bj'),(8,'h','sz'); # connect to physical mysql database by mysql client directly table not_db_tb_0; table not_db_tb_1; # check data select t.* from not_db_tb t order by id;
Mycat 逻辑库
cls0 对应的物理库中的分片表1
cls0 对应的物理库中的分片表2
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。