mycat 采用枚举策略进行分片

本文详细介绍了使用Mycat进行数据库分片的具体步骤,包括在不同分片上创建测试表,配置schema.xml和rule.xml文件实现基于整数的哈希分片策略,以及通过partition-hash-int.txt文件定义具体的分片映射规则。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

0、分别在两个红蓝分片中创建测试表t_pang;

 mysql -h192.168.1.141 -uroot -P3307 -p -D taobao -e"create table t_pang(id int not null,name varchar(20)); "

mysql -h192.168.1.141 -uroot -P3308 -p -D taobao -e"create table t_pang(id int not null,name varchar(20)); "

1、schema.xml

rule="sharding-by-intfile" 

2、rule.xml

[root@s10 conf]# grep -A 5 'sharding-by-intfile' rule.xml 
        <tableRule name="sharding-by-intfile">
                <rule>
                        <columns>sharding_id</columns>
                        <algorithm>hash-int</algorithm>
                </rule>
        </tableRule>
[root@s10 conf]# grep -A 5 'hash-int' rule.xml                      
                     
--
        <function name="hash-int"
                class="io.mycat.route.function.PartitionByFileMap">
                <property name="mapFile">partition-hash-int.txt</property>

                <property name="type">1</property> ##如果枚举元素是字符串的需要设置type类型为1,默认为0是数字
        </function>
       

4、修改partition-hash-int.tx

#10000=0
#10010=1
bj=0
sh=1
DEFAULT_NODE=1 #其他的枚举值的默认存在1号分片

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值