0.前提条件
1.修改schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="MYCAT_DB" checkSQLschema="false" sqlMaxLimit="100">
<!-- auto sharding by id (long) -->
<table name="travelrecord" dataNode="dn1,dn2" rule="auto-sharding-long" />
<table name="user" primaryKey="ID" autoIncrement="true" dataNode="dn1,dn2"
rule="mod-long" />
</schema>
<dataNode name="dn1" dataHost="win-local" database="db1" />
<dataNode name="dn2" dataHost="centos-local" database="db1" />
<dataHost name="win-local" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="win-local-M" url="196.168.1.104:3306" user="root"
password="*******">
</writeHost>
</dataHost>
<dataHost name="centos-local" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="centos-local-M" url="192.168.1.60:3306" user="root"
password="******">
</writeHost>
</dataHost>
</mycat:schema>
2. 修改rule.xml
<tableRule name="mod-long">
<rule>
<columns>id</columns>
<algorithm>mod-long</algorithm>
</rule>
</tableRule>
<function name="mod-long" class="io.mycat.route.function.PartitionByMod">
<!-- how many data nodes -->
<property name="count">2</property>
</function>
3.默认的auto-sharding-long 有三个节点,现在实际只设置了两个节点
[root@base-linux conf]# vi autopartition-long.txt
3.启动mycat
[root@base-linux conf]# /usr/local/src/mycat/bin/mycat console start
4.使用navicat连接mycat
1)创建user表
create table user(id bigint not null auto_increment primary key,name varchar(100));
2)在两个节点都创建了user表 (id%2 == 1 -->dn1 id%2 == 0 -->dn2 )