Mycat资料

(随时更新)

1.MyCat 安装部署,实现数据库分片存储

链接地址:http://www.cnblogs.com/raphael5200/p/5884931.html

主要通过

auto-sharding-long分片规则

    在上面的例子中使用到auto-sharding-long分片规则,在这里要说明一下这个分片规则的实现原理。

    在mycat/conf.rule.xml中定义了分片规则的实现原理  auto-sharding-long 分片规则是这样的:

复制代码
        <tableRule name="auto-sharding-long">
                <rule>
                        <columns>id</columns>
                        <algorithm>rang-long</algorithm>
                </rule>
        </tableRule>

        <function name="rang-long" class="org.opencloudb.route.function.AutoPartitionByLong">
                <property name="mapFile">autopartition-long.txt</property>
        </function>
复制代码

    可见这个TableRule是通过id 来进行分片的,分片的算法是rang-long 下面在算法中使用到了autopartition-long.txt(mycat/conf下),打开看看:

1
2
3
4
5
# range start-end ,data node index
# K=1000,M=10000.
0-500M=0
500M-1000M=1
1000M-1500M=2

    K=1000条记录,M=10000条记录,那么下面三个配置就是0~500万的记录会存在数据库db1的表中,500万~1000万会存在db2的表中,1000万~1500万会存在db3的表中。

原文地址:https://www.cnblogs.com/pursol/p/6405541.html