Mycat學習總結

 

 

 

場景一:node

1.一個全局表 t_testmysql

    a.   經過mycat 操做數據 insert 、delete 數據,則對應的2個datanode中的數據 都會被刪除算法

    b.  2個datanode中的數據不一樣時 ,不會相互同步。sql

  注:貌似從官方描述上來講 ,是會自動同步的。測試

 

   摘自:Mycat 官方開發指南 V1.6.0中ui

 

2.測試分片規則url

 

2.1  分片枚舉spa

   

<?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="employee" primaryKey="ID" dataNode="dn1,dn2"
               rule="sharding-by-intfile" />
    </schema>
    <!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743"
        /> -->
    <dataNode name="dn1" dataHost="localhost1" database="db1" />
    <dataNode name="dn2" dataHost="localhost1" database="db2" />
    <dataNode name="dn3" dataHost="localhost1" database="db3" />
    <!--<dataNode name="dn4" dataHost="sequoiadb1" database="SAMPLE" />
     <dataNode name="jdbc_dn1" dataHost="jdbchost" database="db1" />
    <dataNode    name="jdbc_dn2" dataHost="jdbchost" database="db2" />
    <dataNode name="jdbc_dn3"     dataHost="jdbchost" database="db3" /> -->
    <dataHost name="localhost1" 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="localhost:3307" user="root"
                   password="123456">
            <!-- can have multi read hosts -->
            <readHost host="hostS2" url="localhost:3307" user="root" password="123456" />
        </writeHost>
    </dataHost>
 
</mycat:schema>

 

   create table employee (id int not null primary key,name varchar(100),sharding_id int not null);code

 

   insert into employee(id,name,sharding_id) values(1,'hutuchong',10000);xml

   insert into employee(id,name,sharding_id) values(2,'zhanghui',10010);

 

   這兩條數據會分別查到不一樣的分片上,由於 表配置了這個rule規則

 rule="sharding-by-intfile" ,在rule.xml中配置了算法,對應的文件以下

這個意思是 當值10000時存 index爲0的分片(第一個分片 dn1)

 

2.2 全局表

  

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

<mycat:schema xmlns:mycat="http://io.mycat/">
    
    <!--aps_acct start-->
    <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
        <table name="t_test" type="global" dataNode="aps_acct_node1,aps_acct_node2" />
    </schema>
    <dataNode name="aps_acct_node1" dataHost="aps_acct_host1" database="aps_acct" />
    <dataNode name="aps_acct_node2" dataHost="aps_acct_host2" database="aps_acct" />
    
    <dataHost name="aps_acct_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="localhost:3307" user="root" password="123456">
            <readHost host="hostS2" url="localhost:3307" user="root" password="123456" />
        </writeHost>
    </dataHost>
    <dataHost name="aps_acct_host2" maxCon="1000" minCon="10" balance="0"
              writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
        <heartbeat>select user()</heartbeat>
        <writeHost host="hostM1" url="localhost:3308" user="root" password="123456">
            <readHost host="hostS2" url="localhost:3308" user="root" password="123456" />
        </writeHost>
    </dataHost>
    <!--aps_acct start-->
</mycat:schema>

     參見1

2.3 天然月

     

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

<mycat:schema xmlns:mycat="http://io.mycat/">
    
    <!--aps_acct start-->
    <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
        <table name="t_order" dataNode="aps_acct_node1,aps_acct_node2"  rule="sharding-by-month" />
    </schema>
    <dataNode name="aps_acct_node1" dataHost="aps_acct_host1" database="aps_acct" />
    <dataNode name="aps_acct_node2" dataHost="aps_acct_host2" database="aps_acct" />
    
    <dataHost name="aps_acct_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="localhost:3307" user="root" password="123456">
            <readHost host="hostS2" url="localhost:3307" user="root" password="123456" />
        </writeHost>
    </dataHost>
    <dataHost name="aps_acct_host2" maxCon="1000" minCon="10" balance="0"
              writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
        <heartbeat>select user()</heartbeat>
        <writeHost host="hostM1" url="localhost:3308" user="root" password="123456">
            <readHost host="hostS2" url="localhost:3308" user="root" password="123456" />
        </writeHost>
    </dataHost>
    <!--aps_acct start-->
</mycat:schema>

          

      

CREATE TABLE t_order(id INT NOT NULL PRIMARY KEY,create_time DATETIME NOT NULL);

INSERT INTO t_order(id,create_time) VALUES(1,'2015-01-01')
INSERT INTO t_order(id,create_time) VALUES(2,'2015-02-01')


請檢查文件 rule.xml

須要插入2015年開始的數據

    這樣2條數據就分別進入到 對應的datanode,  因爲每一年有12個月,全部累計須要對應不少datanode

 

   

 

    1,2,3,4...,24,....48....

相關文章
相關標籤/搜索