mycat one群:106088787。
分片规则:字符串拆分hash
一、conf/schema.xml文件
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
<table name="partition_by_hotdate" primaryKey="id" dataNode="dn$0-2"
rule="sharding-by-date" />
</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"/>
<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">
</writeHost>
</dataHost>
</mycat:schema>
二、 conf/rule.xml文件
<tableRule name="sharding-by-date">
<rule>
<columns>create_time</columns>
<algorithm>sharding-by-hotdate</algorithm>
</rule>
</tableRule>
<function name="sharding-by-hotdate" class="io.mycat.route.function.PartitionByHotDate">
<property name="dateFormat">yyyy-MM-dd</property>
<property name="sLastDay">10</property>
<property name="sPartionDay">30</property>
</function>
三、规则文件信息
无
四、测试用到的sql
=============按照 热数据分片================
CREATE TABLE partition_by_hotdate (create_time timestamp NULL ON UPDATE CURRENT_TIMESTAMP ,`db_nm` varchar(20) NULL);
INSERT INTO partition_by_hotdate (create_time,db_nm) VALUES ('2017-10-01', database());
INSERT INTO partition_by_hotdate (create_time,db_nm) VALUES ('2017-10-10', database());
INSERT INTO partition_by_hotdate (create_time,db_nm) VALUES ('2017-10-11', database());
INSERT INTO partition_by_hotdate (create_time,db_nm) VALUES ('2017-10-21', database());
INSERT INTO partition_by_hotdate (create_time,db_nm) VALUES ('2017-10-31', database());
INSERT INTO partition_by_hotdate (create_time,db_nm) VALUES ('2017-11-30', database());
select * from partition_by_hotdate;
五、注意事项
1、数据的及时移动
六、参数说明
1、dataFormat:时间格式化
2、sLastDay:热数据的天数
3、sPartionDay:冷数据的分片天数(按照天数分片)