mycat分表

mycat分表

1.schema.xml配置文件

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
	<schema name="khtdb" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn1">
	   <table name="customer" dataNode="dn2" ></table>
	   <table name="orders" dataNode="dn1,dn2" rule="mod_rule"></table>
	</schema>
	<dataNode name="dn1" dataHost="host1" database="orders" />
	<dataNode name="dn2" dataHost="host2" database="orders" />
	<dataHost name="host1" maxCon="1000" minCon="10" balance="0"
			  writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
    <writeHost host="hostM1" url="192.168.2.128:3306" user="root"
				   password="kht123">
    </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>
    <writeHost host="hostM2" url="192.168.2.129:3306" user="root"
				   password="kht123">
    </writeHost>
	</dataHost>
</mycat:schema>

2.rule.xml配置文件修改

	<tableRule name="mod_rule">
			<rule>
				<columns>customer_id</columns>
				<algorithm>mod-long</algorithm>
			</rule>
	</tableRule>
	
	<tableRule name="rule1">
		<rule>
			<columns>id</columns>
			<algorithm>func1</algorithm>
		</rule>
	</tableRule>
	<function name="mod-long" class="io.mycat.route.function.PartitionByMod">
		<!-- how many data nodes 实际节点个数 -->
		<property name="count">2</property>
	</function>

3.在另外一台mysql中执行orders的建表语句,重启mycat,并在mycat执行插入语句,查看效果

#订单表 rows:600万
CREATE TABLE orders(
id INT AUTO_INCREMENT,
order_type INT,
customer_id INT,
amount DECIMAL(10,2),
PRIMARY KEY(id)
);
#在 mycat 里向 orders 表插入数据,INSERT 字段不能省略
INSERT INTO orders(id,order_type,customer_id,amount) VALUES (1,101,100,100100);
INSERT INTO orders(id,order_type,customer_id,amount) VALUES(2,101,100,100300);
INSERT INTO orders(id,order_type,customer_id,amount) VALUES(3,101,101,120000);
INSERT INTO orders(id,order_type,customer_id,amount) VALUES(4,101,101,103000);
INSERT INTO orders(id,order_type,customer_id,amount) VALUES(5,102,101,100400);
INSERT INTO orders(id,order_type,customer_id,amount) VALUES(6,102,100,100020);

4.在mycat、dn1、dn2中查看orders表数据,分表成功

mycat分表

mycat分表

上一篇:用u盘和iso镜像文件装win8.1系统


下一篇:窗体设置