crs32算法,分库字段类型支撑int和varchar.
1.rule.xml
-
<tableRule name="crc32slot">
-
<rule>
-
<columns>id</columns>
-
<algorithm>crc32slot</algorithm>
-
</rule>
-
</tableRule>
-
<function name="crc32slot"
-
class="io.mycat.route.function.PartitionByCRC32PreSlot">
-
<property name="count">6</property><!-- 要分片的数据库节点数量,必须指定,否则没法分片 -->
-
</function>
count=6指定需要分库的个数.
2.schema.xml
-
<?xml version="1.0"?>
-
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
-
<mycat:schema xmlns:mycat="">
-
-
<schema name="logdb" checkSQLschema="false" sqlMaxLimit="100">
-
<table name="tb_log_t" primaryKey="ID" autoIncrement="true" dataNode="dn1,dn2,dn3,dn4,dn5,dn6" rule="mod-long" />
-
<table name="tb_user_t" dataNode="dn1,dn2,dn3,dn4,dn5,dn6" rule="sharding-by-intfile-provcode" />
-
<table name="tb_user_detail_t" dataNode="dn1,dn2,dn3,dn4,dn5,dn6" rule="auto-sharding-long-userid" />
-
<table name="tb_user_murmur_t" dataNode="dn1,dn2,dn3,dn4,dn5,dn6" rule="sharding-by-murmur" />
-
<table name="tb_user_murmur_string_t" dataNode="dn1,dn2,dn3,dn4,dn5,dn6" rule="sharding-by-murmur-userid" />
-
<table name="tb_user_crc32slot_t" dataNode="dn1,dn2,dn3,dn4,dn5,dn6" rule="crc32slot" />
-
</schema>
-
<schema name="coss03" checkSQLschema="false" sqlMaxLimit="100" dataNode="dnoss03"/>
-
<dataNode name="dn1" dataHost="localhost1" database="log01" />
-
<dataNode name="dn2" dataHost="localhost1" database="log02" />
-
<dataNode name="dn3" dataHost="localhost1" database="log03" />
-
<dataNode name="dn4" dataHost="localhost1" database="log04" />
-
<dataNode name="dn5" dataHost="localhost1" database="log05" />
-
<dataNode name="dn6" dataHost="localhost1" database="log06" />
-
<dataNode name="dnoss03" dataHost="localhost1" database="oss03" />
-
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"
-
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
-
<heartbeat>select user()</heartbeat>
-
<!-- can have multi write hosts -->
-
<writeHost host="hostM1" url="192.168.56.141:3306" user="root"
-
password="mysql">
-
<!-- can have multi read hosts -->
-
<readHost host="hostS2" url="192.168.56.142:3306" user="root" password="mysql" />
-
</writeHost>
-
</dataHost>
-
</mycat:schema>
3.创建表
CREATE TABLE `tb_user_crc32slot_t` (
`id` varchar(32) NOT NULL,
`name` varchar(64) DEFAULT NULL,
`createtime` datetime DEFAULT CURRENT_TIMESTAMP,
`moditytime` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
写入数据:
insert into tb_user_crc32slot_t(id,name) values('a0002','name1');
insert into tb_user_crc32slot_t(id,name) values('a0003','name1');
insert into tb_user_crc32slot_t(id,name) values('a0004','name1');
insert into tb_user_crc32slot_t(id,name) values('a0005','name1');
insert into tb_user_crc32slot_t(id,name) values('a0006','name1');
insert into tb_user_crc32slot_t(id,name) values('a0007','name1');
insert into tb_user_crc32slot_t(id,name) values('a0008','name1');
insert into tb_user_crc32slot_t(id,name) values('a0009','name1');
insert into tb_user_crc32slot_t(id,name) values('a0010','name1');
insert into tb_user_crc32slot_t(id,name) values('a0011','name1');
insert into tb_user_crc32slot_t(id,name) values('a0012','name1');
insert into tb_user_crc32slot_t(id,name) values('a0013','name1');
insert into tb_user_crc32slot_t(id,name) values('a0014','name1');
insert into tb_user_crc32slot_t(id,name) values('a0015','name1');
-- The End --
阅读(4723) | 评论(0) | 转发(0) |