本文主要是介绍mycat水平分库-对用户id取模,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
schema.xml:
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/"><schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100" ><table name="tb_user" dataNode="dn1,dn2" rule="my_mod_rule"/></schema><dataNode name="dn1" dataHost="host1" database="jeesun_user" /><dataNode name="dn2" dataHost="host2" database="jeesun_user" /><dataHost name="host1" 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.31.52:3306" user="root"password="root12"></writeHost></dataHost><dataHost name="host2" 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.31.52:3308" user="root"password="root12"></writeHost></dataHost></mycat:schema>
rule.xml:
<tableRule name="my_mod_rule"><rule><columns>user_id</columns><algorithm>my_mod-long</algorithm></rule></tableRule>
<function name="my_mod-long" class="io.mycat.route.function.PartitionByMod"><!-- how many data nodes --><property name="count">2</property></function>
这篇关于mycat水平分库-对用户id取模的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!