mycat单库多表

首先要使用单库多表功能,mycat要1.6.5及以后版本

然后conf/schema.xml的table标签subTables指定表名字,例如我们要分表为order1,order2,order3则可以填写subTables=”order$1-3″

然后conf/rule.xml里面配置的function以前需要指定数据库数量的,现在改成表数量即可。

 

下面给出配置文件的demo:

 


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">

<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="schema1" checkSQLschema="true" sqlMaxLimit="100" >
<table name="user" primaryKey="id" autoIncrement="true" dataNode="d1,d2,d3,d4,d5" rule="rule1"/>

<table name="order" primaryKey="id" autoIncrement="true" subTables="order$1-3" dataNode="d1" rule="rule2"/>
</schema>

<dataNode name="d1" dataHost="localhost1" database="db1"/>
<dataNode name="d2" dataHost="localhost1" database="db2"/>
<dataNode name="d3" dataHost="localhost1" database="db3"/>
<dataNode name="d4" dataHost="localhost1" database="db4"/>
<dataNode name="d5" dataHost="localhost1" database="db5"/>

<dataHost name="localhost1" writeType="0" switchType="1" slaveThreshold="100" balance="1" dbType="mysql" maxCon="10" minCon="1" dbDriver="native">
<heartbeat>show status like 'wsrep%'</heartbeat>
<writeHost host="hostM1" url="127.0.0.1:3306" user="root" password="root" >
</writeHost>
</dataHost>
</mycat:schema >


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mycat:rule SYSTEM "rule.dtd">

<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="rule1">
<rule>
<columns>id</columns>
<algorithm>func1</algorithm>
</rule>
</tableRule>
<tableRule name="rule2">
<rule>
<columns>id</columns>
<algorithm>func2</algorithm>
</rule>
</tableRule>

<function name="func1" class="io.mycat.route.function.PartitionByMod">
<!-- how many data nodes -->
<property name="count">5</property>
</function>

<function name="func2" class="io.mycat.route.function.PartitionByMod">
<!-- how many data nodes -->
<property name="count">3</property>
</function>

</mycat:rule >

发表评论

电子邮件地址不会被公开。 必填项已用*标注