1 找到conf/schema.xml修改

2 取模的路由规则
和轮询一样,取模有什么好处,有什么坏处?
优点:利用的写的负载均衡效果,写入速度很快
缺点:批量写入,失败后事务的回滚有难度!代表写都成功,或都失败
批量写入:100
第99 条失败了,执行数据的回滚!
db1 db2 db3 (跨数据库的回滚,非常难,很耗费性能)
此规则为对分片字段求摸运算。
	<tableRule name="leige-mo-rule">
		<rule>
			<columns>id</columns>
			<algorithm>leige-mo-rule-hash</algorithm>
		</rule>
	</tableRule>
	<function name="leige-mo-rule-hash" class="io.mycat.route.function.PartitionByMod"> 
    	<!-- 有多个少datanode就配置几 -->
    	<property name="count">3</property> 
	</function>配置说明: 上面columns 标识将要分片的表字段,algorithm 分片函数, 此种配置非常明确即根据id进行十进制求模预算,相比固定分片hash,此种在批量插入时可能存在批量插入单 事务插入多数据分片,增大事务一致性难度
3 测试
创建表
CREATE TABLE sys_dept(
  id INT PRIMARY KEY ,
  deptname VARCHAR(20) NOT NULL
);插入数据测试
EXPLAIN INSERT INTO sys_dept(id,deptname) VALUES(2,'开发3部');当id=1 时 1%3=1 所以数据到db2

当id=2 时 2%3=2 所以数据到db3

当id=3 时 3%3=0 所以数据到db1





![[附源码]计算机毕业设计Python的黄河文化科普网站(程序+源码+LW文档)](https://img-blog.csdnimg.cn/3349fedd2d514c5da1cbfcb31676f0ed.png)





![[附源码]计算机毕业设计Python的网上点餐系统(程序+源码+LW文档)](https://img-blog.csdnimg.cn/ae379ac525664ab1b57deea86f5390a9.png)
![[附源码]计算机毕业设计Python的汽车租赁系统(程序+源码+LW文档)](https://img-blog.csdnimg.cn/ace89fafe29645d792bd5ef7fa886ff6.png)





