分片 | 连续分片 | 离散分片 |
---|---|---|
优点 | 扩容无需迁移数据 范围条件查询消耗资源少 |
并发访问能力增强 范围条件查询性能提升 |
缺点 | 存在数据热点的可能性 并发访问能力受限于单一或少量DataNode |
数据扩容比较困难,涉及到数据迁移问题 数据库连接消耗比较多 |
TableRule :
标识名称
(唯一)。<tableRule name="auto-sharding-long">
<rule>
<columns>idcolumns>
<algorithm>rang-longalgorithm>
rule>
tableRule>
Function :
<function name="rang-long" class="io.mycat.route.function.AutoPartitionByLong">
<property name="mapFile">autopartition-long.txtproperty>
function>
schema.xml
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="luckcat" checkSQLschema="false" sqlMaxLimit="100">
<table name="auto_sharding_long" primaryKey="id" dataNode="dn0,dn1,dn2" rule="auto-sharding-long"/>
schema>
<dataNode name="dn0" dataHost="dh-1" database="db0"/>
<dataNode name="dn1" dataHost="dh-1" database="db1"/>
<dataNode name="dn2" dataHost="dh-1" database="db2"/>
<dataNode name="dn3" dataHost="dh-1" database="db3"/>
<dataNode name="dn4" dataHost="dh-1" database="db4"/>
<dataNode name="dn5" dataHost="dh-1" database="db5"/>
<dataNode name="dn6" dataHost="dh-1" database="db6"/>
<dataNode name="dn7" dataHost="dh-1" database="db7"/>
<dataNode name="dn8" dataHost="dh-1" database="db8"/>
<dataNode name="dn9" dataHost="dh-1" database="db9"/>
<dataNode name="dn10" dataHost="dh-1" database="db10"/>
<dataHost name="dh-1" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"
switchType="1" slaveThreshold="100">
<heartbeat>select user()heartbeat>
<writeHost host="hostM1" url="localhost:3306" user="root" password="123456"/>
dataHost>
mycat:schema>
rule.xml
<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="auto-sharding-long">
<rule>
<columns>agecolumns>
<algorithm>rang-longalgorithm>
rule>
tableRule>
<function name="rang-long" class="io.mycat.route.function.AutoPartitionByLong">
<property name="mapFile">autopartition-long.txtproperty>
<property name="defaultNode">0property>
function>
mycat:rule>
autopartition-long.txt
# range start-end ,data node index
# K=1000,M=10000.
0-2M=0
2M-3M=1
3M-6M=2
test.sql
CREATE TABLE auto_sharding_long (`age` int NOT NULL ,`db_nm` varchar(20) NULL);
INSERT INTO auto_sharding_long (age,db_nm) VALUES (20000, database());
INSERT INTO auto_sharding_long (age,db_nm) VALUES (25000, database());
INSERT INTO auto_sharding_long (age,db_nm) VALUES (35000, database());
select * from auto_sharding_long;
schema.xml
<table name="sharding_by_day" primaryKey="id" dataNode="dn$0-2" rule="sharding-by-day" />
rule.xml
<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="sharding-by-day">
<rule>
<columns>create_timecolumns>
<algorithm>part-by-dayalgorithm>
rule>
tableRule>
<function name="part-by-day"
class="io.mycat.route.function.PartitionByDate">
<property name="dateFormat">yyyy-MM-ddproperty>
<property name="sBeginDate">2017-10-01property>
<property name="sPartionDay">10property>
function>
mycat:rule>
test.sql
CREATE TABLE sharding_by_day (create_time timestamp NULL ON UPDATE CURRENT_TIMESTAMP ,`db_nm` varchar(20) NULL);
INSERT INTO sharding_by_day (create_time,db_nm) VALUES ('2017-10-01', database());
INSERT INTO sharding_by_day (create_time,db_nm) VALUES ('2017-10-10', database());
INSERT INTO sharding_by_day (create_time,db_nm) VALUES ('2017-10-11', database());
INSERT INTO sharding_by_day (create_time,db_nm) VALUES ('2017-10-21', database());
INSERT INTO sharding_by_day (create_time,db_nm) VALUES ('2017-10-31', database());
select * from sharding_by_day;
-- 以上测试结果中有个错误,因为配置的dataNode节点数为3,而2017-10-31为2017-10-01后的第四个10天中的第一天,因此需要至少4个dataNode,节点不够就报如上错误了。
schema.xml
<table name="sharding_by_hour" primaryKey="id" dataNode="dn$0-2" rule="sharding-by-hour" />
rule.xml
<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="sharding-by-hour">
<rule>
<columns>sharding_colcolumns>
<algorithm>sharding-by-houralgorithm>
rule>
tableRule>
<function name="sharding-by-hour" class="io.mycat.route.function.LatestMonthPartion">
<property name="splitOneDay">3property>
function>
mycat:rule>
test.sql
-- 单月内按照小时拆分,最小粒度是小时,一天最多可以有24个分片,最少1个分片,下个月从头开始循环,每个月末需要手工清理数据。
-- 字段为字符串类型,yyyymmddHH 10位。
CREATE TABLE sharding_by_hour (create_time timestamp NULL ON UPDATE CURRENT_TIMESTAMP ,`db_nm` varchar(20) NULL,sharding_col varchar(10) null);
INSERT INTO sharding_by_hour (sharding_col,create_time,db_nm) VALUES ('2017100101','2017-10-01', database());
INSERT INTO sharding_by_hour (sharding_col,create_time,db_nm) VALUES ('2017100108','2017-10-01', database());
INSERT INTO sharding_by_hour (sharding_col,create_time,db_nm) VALUES ('2017100109','2017-10-01', database());
INSERT INTO sharding_by_hour (sharding_col,create_time,db_nm) VALUES ('2017100116','2017-10-01', database());
INSERT INTO sharding_by_hour (sharding_col,create_time,db_nm) VALUES ('2017100117','2017-10-01', database());
INSERT INTO sharding_by_hour (sharding_col,create_time,db_nm) VALUES ('2017100123','2017-10-01', database());
select * from sharding_by_hour;
schema.xml
<table name="sharding_by_month" primaryKey="id" dataNode="dn$0-2" rule="sharding-by-month" />
rule.xml
<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="sharding-by-month">
<rule>
<columns>create_timecolumns>
<algorithm>sharding-by-monthalgorithm>
rule>
tableRule>
<function name="sharding-by-month" class="io.mycat.route.function.PartitionByMonth">
<property name="dateFormat">yyyy-MM-ddproperty>
<property name="sBeginDate">2017-10-01property>
<property name="sEndDate">2017-12-30property>
function>
mycat:rule>
test.sql
CREATE TABLE sharding_by_month (create_time timestamp NULL ON UPDATE CURRENT_TIMESTAMP ,`db_nm` varchar(20) NULL);
INSERT INTO sharding_by_month (create_time,db_nm) VALUES ('2017-10-01', database());
INSERT INTO sharding_by_month (create_time,db_nm) VALUES ('2017-10-30', database());
INSERT INTO sharding_by_month (create_time,db_nm) VALUES ('2017-11-11', database());
INSERT INTO sharding_by_month (create_time,db_nm) VALUES ('2017-11-21', database());
INSERT INTO sharding_by_month (create_time,db_nm) VALUES ('2017-12-01', database());
INSERT INTO sharding_by_month (create_time,db_nm) VALUES ('2017-12-31', database());
INSERT INTO sharding_by_month (create_time,db_nm) VALUES ('2018-01-01', database());
INSERT INTO sharding_by_month (create_time,db_nm) VALUES ('2018-01-31', database());
select * from sharding_by_month
-- 注意
-- * schema里的table的dataNode节点数必须:大于rule的开始时间按照分片数计算到现在的个数
-- * 按照自然月计算(无论是28、30、31天都是一个月的)
-- * 分片节点个数可以后增加,但是必须符合第一点说明。
schema.xml
<table name="sharding_by_intfile" primaryKey="id" dataNode="dn$0-2" rule="sharding-by-intfile" />
rule.xml
<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="sharding-by-intfile">
<rule>
<columns>agecolumns>
<algorithm>hash-intalgorithm>
rule>
tableRule>
<function name="hash-int" class="io.mycat.route.function.PartitionByFileMap">
<property name="mapFile">partition-hash-int.txtproperty>
<property name="type">0property>
<property name="defaultNode">0property>
function>
mycat:rule>
partition-hash-int.txt
# 枚举项=节点标识,枚举项可以是数字和字符(非汉字)
11=1
12=2
test.sql
-- 通过在配置文件中配置可能的枚举id,指定数据分布到不同的物理节点上,本规则适用于按照省份或区县来拆分数据类业务。
CREATE TABLE sharding_by_intfile (`age` int NOT NULL ,`db_nm` varchar(20) NULL);
INSERT INTO `sharding_by_intfile` (age,db_nm) VALUES (10, database());
INSERT INTO `sharding_by_intfile` (age,db_nm) VALUES (11, database());
INSERT INTO `sharding_by_intfile` (age,db_nm) VALUES (12, database());
select * from `sharding_by_intfile`;
schema.xml
<table name="sharding_by_substring" primaryKey="id" dataNode="dn$0-2" rule="sharding-by-substring" />
rule.xml
<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="sharding-by-substring">
<rule>
<columns>user_idcolumns>
<algorithm>sharding-by-substringalgorithm>
rule>
tableRule>
<function name="sharding-by-substring" class="io.mycat.route.function.PartitionDirectBySubString">
<property name="startIndex">0property>
<property name="size">2property>
<property name="partitionCount">3property>
<property name="defaultPartition">0property>
function>
mycat:rule>
test.sql
-- 在程序运行阶段,由程序自主决定路由到哪个分片。
CREATE TABLE sharding_by_substring (`user_id` varchar(20) NOT NULL ,`db_nm` varchar(20) NULL);
INSERT INTO `sharding_by_substring` (user_id,db_nm) VALUES ('05-10000', database());
INSERT INTO `sharding_by_substring` (user_id,db_nm) VALUES ('02-10001', database());
INSERT INTO `sharding_by_substring` (user_id,db_nm) VALUES ('03-10002', database());
select * from `sharding_by_substring`;
schema.xml
<table name="sharding_by_mod" primaryKey="id" dataNode="dn$0-2" rule="sharding-mod-long" />
rule.xml
<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="sharding-mod-long">
<rule>
<columns>idcolumns>
<algorithm>mod-longalgorithm>
rule>
tableRule>
<function name="mod-long" class="io.mycat.route.function.PartitionByMod">
<property name="count">3property>
function>
mycat:rule>
test.sql
CREATE TABLE `sharding_by_mod` (id int(10) null,`db_nm` varchar(20) NULL);
INSERT INTO `sharding_by_mod` (id,db_nm) VALUES (1, database());
INSERT INTO `sharding_by_mod` (id,db_nm) VALUES (2, database());
INSERT INTO `sharding_by_mod` (id,db_nm) VALUES (3, database());
INSERT INTO `sharding_by_mod` (id,db_nm) VALUES (10, database());
select * from sharding_by_mod;
schema.xml
<table name="sharding_by_stringhash" primaryKey="ord_no" dataNode="dn$0-2" rule="sharding-by-stringhash" />
rule.xml
<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="sharding-by-stringhash">
<rule>
<columns>ord_nocolumns>
<algorithm>sharding-by-stringhashalgorithm>
rule>
tableRule>
<function name="sharding-by-stringhash" class="io.mycat.route.function.PartitionByString">
<property name="partitionLength">512property>
<property name="partitionCount">2property>
<property name="hashSlice">-6:0property>
function>
mycat:rule>
test.sql
-- 此规则是截取字符串中的int数值的hash分片。
CREATE TABLE sharding_by_stringhash (ord_no varchar(20) NULL,`db_nm` varchar(20) NULL);
INSERT INTO `sharding_by_stringhash` (ord_no,db_nm) VALUES (171022237582, database());
INSERT INTO `sharding_by_stringhash` (ord_no,db_nm) VALUES (171022553756, database());
select * from sharding_by_stringhash;
schema.xml
<table name="sharding_by_murmurhash" primaryKey="id" dataNode="dn$0-2" rule="sharding-by-murmurhash" />
rule.xml
<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="sharding-by-murmurhash">
<rule>
<columns>idcolumns>
<algorithm>sharding-by-murmurhashalgorithm>
rule>
tableRule>
<function name="sharding-by-murmurhash" class="io.mycat.route.function.PartitionByMurmurHash">
<property name="seed">0property>
<property name="count">2property>
<property name="virtualBucketTimes">160property>
function>
mycat:rule>
test.sql
-- 一致性hash算法有效解决了分布式数据的扩容问题。因为此规则优点在于扩容时迁移数据量比较少,前提是分片节点比较多,虚拟节点分配多些。
-- 虚拟节点分配的少就会造成数据分布不够均匀。但如果实际分片数据比较少,迁移量也会比较多。
CREATE TABLE sharding_by_murmurhash (id int(10) null,`db_nm` varchar(20) NULL);
INSERT INTO `sharding_by_murmurhash` (id,db_nm) VALUES (1, database());
INSERT INTO `sharding_by_murmurhash` (id,db_nm) VALUES (2, database());
INSERT INTO `sharding_by_murmurhash` (id,db_nm) VALUES (3, database());
INSERT INTO `sharding_by_murmurhash` (id,db_nm) VALUES (4, database());
INSERT INTO `sharding_by_murmurhash` (id,db_nm) VALUES (5, database());
INSERT INTO `sharding_by_murmurhash` (id,db_nm) VALUES (6, database());
INSERT INTO `sharding_by_murmurhash` (id,db_nm) VALUES (7, database());
INSERT INTO `sharding_by_murmurhash` (id,db_nm) VALUES (8, database());
INSERT INTO `sharding_by_murmurhash` (id,db_nm) VALUES (9, database());
INSERT INTO `sharding_by_murmurhash` (id,db_nm) VALUES (10, database());
select * from sharding_by_murmurhash;
schema.xml
<table name="sharding_by_rang_mod" primaryKey="id" dataNode="dn$0-10" rule="sharding-by-rang-mod" />
rule.xml
<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="sharding-by-rang-mod">
<rule>
<columns>idcolumns>
<algorithm>sharding-by-rang-modalgorithm>
rule>
tableRule>
<function name="sharding-by-rang-mod" class="io.mycat.route.function.PartitionByRangeMod">
<property name="mapFile">partition-range-mod.txtproperty>
<property name="defaultNode">0property>
function>
mycat:rule>
partition-range-mod.txt
# range start-end ,data node group size
0-200M=3
200M1-400M=1
400M1-600M=4
600M1-800M=2
test.sql
-- 该算法先进行范围分片,计算出分片组,组内再求模,综合了范围分片和求模分片的优点。分片组内使用求模可以保证组内的数据分布比较均匀,
-- 分片组之间采用范围分片可以兼顾范围分片的特点。事先规定好分片的数量,数据扩容时按分片组扩容,则原有分片组的数据不需要迁移。由于
-- 分片组内的数据分布比较均匀,所以分片组内可以避免热点数据问题。
CREATE TABLE sharding_by_rang_mod (id bigint null,`db_nm` varchar(20) NULL);
INSERT INTO `sharding_by_rang_mod` (id,db_nm) VALUES (1000, database());
INSERT INTO `sharding_by_rang_mod` (id,db_nm) VALUES (1002, database());
INSERT INTO `sharding_by_rang_mod` (id,db_nm) VALUES (30000, database());
INSERT INTO `sharding_by_rang_mod` (id,db_nm) VALUES (30004, database());
INSERT INTO `sharding_by_rang_mod` (id,db_nm) VALUES (40000, database());
INSERT INTO `sharding_by_rang_mod` (id,db_nm) VALUES (40005, database());
INSERT INTO `sharding_by_rang_mod` (id,db_nm) VALUES (60005, database());
INSERT INTO `sharding_by_rang_mod` (id,db_nm) VALUES (60006, database());
INSERT INTO `sharding_by_rang_mod` (id,db_nm) VALUES (80006, database());
INSERT INTO `sharding_by_rang_mod` (id,db_nm) VALUES (60008, database());
select * from sharding_by_rang_mod;
schema.xml
<table name="sharding_by_date_hash" primaryKey="id" dataNode="dn$0-10" rule="sharding-by-range-date-hash" />
rule.xml
<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="sharding-by-range-date-hash">
<rule>
<columns>create_timecolumns>
<algorithm>sharding-by-range-date-hashalgorithm>
rule>
tableRule>
<function name="sharding-by-range-date-hash" class="io.mycat.route.function.PartitionByRangeDateHash">
<property name="dateFormat">yyyy-MM-dd HH:mm:ssproperty>
<property name="sBeginDate">2018-01-31 00:00:00property>
<property name="sPartionDay">30property>
<property name="groupPartionSize">10property>
function>
mycat:rule>
test.sql
-- 其思想与范围求模一致,由于日期取模方法会出现数据热点问题,所以先根据日期分组,再根据时间hash使得短期内数据分布得更均匀。
-- 其优点是可以避免扩容时的数据迁移,又可以在一定程度上避免范围分片的热点问题,要求日期格式尽量精确,不然达不到局部均匀的目的。
CREATE TABLE `sharding_by_date_hash` (`create_time` datetime NOT NULL,`db_nm` varchar(20) NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `sharding_by_date_hash` (create_time,db_nm) VALUES ('2018-01-12 00:01:02', database());
INSERT INTO `sharding_by_date_hash` (create_time,db_nm) VALUES ('2018-01-21 01:02:09', database());
INSERT INTO `sharding_by_date_hash` (create_time,db_nm) VALUES ('2018-01-28 12:00:12', database());
INSERT INTO `sharding_by_date_hash` (create_time,db_nm) VALUES ('2018-01-02 11:00:00', database());
INSERT INTO `sharding_by_date_hash` (create_time,db_nm) VALUES ('2018-02-26 10:00:09', database());
INSERT INTO `sharding_by_date_hash` (create_time,db_nm) VALUES ('2018-03-01 22:01:02', database());
INSERT INTO `sharding_by_date_hash` (create_time,db_nm) VALUES ('2018-02-02 17:09:08', database());
INSERT INTO `sharding_by_date_hash` (create_time,db_nm) VALUES ('2018-02-23 11:00:04', database());
INSERT INTO `sharding_by_date_hash` (create_time,db_nm) VALUES ('2018-02-24 18:12:09', database());
INSERT INTO `sharding_by_date_hash` (create_time,db_nm) VALUES ('2018-02-21 07:12:00', database());
select * from sharding_by_date_hash;
schema.xml
<table name="sharding_by_pattern" primaryKey="id" dataNode="dn$0-10" rule="sharding-by-pattern" />
rule.xml
<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="sharding-by-pattern">
<rule>
<columns>idcolumns>
<algorithm>sharding-by-patternalgorithm>
rule>
tableRule>
<function name="sharding-by-pattern" class="io.mycat.route.function.PartitionByPattern">
<property name="mapFile">partition-pattern.txtproperty>
<property name="defaultNode">0property>
<property name="patternValue">256property>
function>
mycat:rule>
partition-pattern.txt
# id patition range start-end, data node index
## first host configuration
1-32=0
33-64=1
65-96=2
97-128=3
## second host configuration
129-160=4
161-192=5
193-224=6
225-256=7
0-0=7
test.sql
CREATE TABLE sharding_by_pattern (id varchar(20) null,`db_nm` varchar(20) NULL);
INSERT INTO `sharding_by_pattern` (id,db_nm) VALUES (1000, database());
INSERT INTO `sharding_by_pattern` (id,db_nm) VALUES (1002, database());
INSERT INTO `sharding_by_pattern` (id,db_nm) VALUES (30000, database());
INSERT INTO `sharding_by_pattern` (id,db_nm) VALUES (30004, database());
INSERT INTO `sharding_by_pattern` (id,db_nm) VALUES (40000, database());
INSERT INTO `sharding_by_pattern` (id,db_nm) VALUES (40005, database());
INSERT INTO `sharding_by_pattern` (id,db_nm) VALUES (60005, database());
INSERT INTO `sharding_by_pattern` (id,db_nm) VALUES (60006, database());
INSERT INTO `sharding_by_pattern` (id,db_nm) VALUES (80006, database());
INSERT INTO `sharding_by_pattern` (id,db_nm) VALUES ("abcd0", database());
select * from sharding_by_pattern;
schema.xml
<table name="sharding_by_ascii" primaryKey="id" dataNode="dn$0-10" rule="partition-by-ascii" />
rule.xml
<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="partition-by-ascii">
<rule>
<columns>idcolumns>
<algorithm>sharding-by-pattern-asciialgorithm>
rule>
tableRule>
<function name="sharding-by-pattern-ascii" class="io.mycat.route.function.PartitionByPrefixPattern">
<property name="mapFile">partition-pattern-ascii.txtproperty>
<property name="patternValue">256property>
<property name="prefixLength">5property>
function>
mycat:rule>
partition-pattern-ascii.txt
# id patition range start-end, data node index
## first host configuration
1-32=0
33-64=1
65-96=2
97-128=3
## second host configuration
129-160=4
161-192=5
193-224=6
225-256=7
0-0=7
test.sql
-- 此种规则类似于取模范围约束,此规则支持数据符号字母取模。
CREATE TABLE sharding_by_ascii (id varchar(20) null,`db_nm` varchar(20) NULL);
INSERT INTO `sharding_by_ascii` (id,db_nm) VALUES ("1000a", database());
INSERT INTO `sharding_by_ascii` (id,db_nm) VALUES ("1002A", database());
INSERT INTO `sharding_by_ascii` (id,db_nm) VALUES (30000, database());
INSERT INTO `sharding_by_ascii` (id,db_nm) VALUES (30004, database());
INSERT INTO `sharding_by_ascii` (id,db_nm) VALUES ("4000B", database());
INSERT INTO `sharding_by_ascii` (id,db_nm) VALUES ("4000b", database());
INSERT INTO `sharding_by_ascii` (id,db_nm) VALUES (60007, database());
INSERT INTO `sharding_by_ascii` (id,db_nm) VALUES (60006, database());
INSERT INTO `sharding_by_ascii` (id,db_nm) VALUES (80006, database());
INSERT INTO `sharding_by_ascii` (id,db_nm) VALUES ("abcd0", database());
select * from sharding_by_ascii;
schema.xml
<table name="sharding_by_long" primaryKey="id" dataNode="dn$0-10" rule="sharding-by-long" />
rule.xml
<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="sharding-by-long">
<rule>
<columns>idcolumns>
<algorithm>sharding-by-longalgorithm>
rule>
tableRule>
<function name="sharding-by-long" class="io.mycat.route.function.PartitionByLong">
<property name="partitionCount">2,1property>
<property name="partitionLength">256,512property>
function>
mycat:rule>
test.sql
-- 本条规则类似于十进制的求模运算,区别在于是二进制的操作,是取id的二进制低10位,即id二进制&1111111111。此算法的优点在
-- 于如果按照十进制取模运算,则在连续插入1~10时,1~10会被分到1~10个分片,增大了插入事务的控制难度。而此算法根据二进制则
-- 可能会分到连接的分片,降低了插入事务的控制难度。
CREATE TABLE sharding_by_long (id int(10) null,`db_nm` varchar(20) NULL);
INSERT INTO `sharding_by_long` (id,db_nm) VALUES (1000, database());
INSERT INTO `sharding_by_long` (id,db_nm) VALUES (1002, database());
INSERT INTO `sharding_by_long` (id,db_nm) VALUES (30000, database());
INSERT INTO `sharding_by_long` (id,db_nm) VALUES (30004, database());
INSERT INTO `sharding_by_long` (id,db_nm) VALUES (4000, database());
INSERT INTO `sharding_by_long` (id,db_nm) VALUES (4000, database());
INSERT INTO `sharding_by_long` (id,db_nm) VALUES (60007, database());
INSERT INTO `sharding_by_long` (id,db_nm) VALUES (60006, database());
INSERT INTO `sharding_by_long` (id,db_nm) VALUES (80006, database());
INSERT INTO `sharding_by_long` (id,db_nm) VALUES (0, database());
select * from sharding_by_long;
单分片表数据量为1000W
左右。最频繁的或者最重要
的查询条件。迁移问题
(范围类,范围取模类不需要迁移,哈希类需要迁移)。关联关系的表配置相同分片规则
(ER思想,为了应用join等复杂sql),一对多对应关系一般按多的那一方切分
。全局表
。源码链接: https://download.csdn.net/download/Gusand/12102557
参考:
推荐博客:https://blog.csdn.net/ygqygq2/article/details/78390985
在线教程:http://www.mycat.io/document/mycat-definitive-guide.pdf