zoukankan      html  css  js  c++  java
  • mycat分表

    mycat分表

    1.schema.xml配置文件

    <?xml version="1.0"?>
    <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
    <mycat:schema xmlns:mycat="http://io.mycat/">
    	<schema name="orders1" 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="orders1" />
    	<dataNode name="dn2" dataHost="host2" database="orders1" />
    	<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表数据,分表成功

  • 相关阅读:
    重读《从菜鸟到测试架构师》-- 职业生涯的考虑
    重读《从菜鸟到测试架构师》-- 从专家到高手
    重读《从菜鸟到测试架构师》-- 开发团队做的远不仅是开发
    重读《从菜鸟到测试架构师》-- 测试专家的第一步
    重读《从菜鸟到测试架构师》-- 前篇
    使用Nodejs+Protractor搭建测试环境
    简单的算法题之合并数组
    性能测试流程
    性能测试基础
    电脑木马
  • 原文地址:https://www.cnblogs.com/khtt/p/15211761.html
Copyright © 2011-2022 走看看