Mycat-based database subtables

There are two ways to subtable a database

  • vertical partitioning
    A database consists of many tables, each of which corresponds to a different business. Vertical slicing refers to classifying tables by business and distributing them over different databases, thus sharing data or pressure among different libraries.
    Advantage:

    - Clear business and clear rules after the split;
    - Easy integration or expansion between systems;
    - Data maintenance is simple.
**Disadvantages:**
 - Some business tables cannot join, they can only be solved by interface, which improves the system complexity;
 - There is a single library performance bottleneck due to different constraints of each business, which makes it difficult to expand data and improve performance;
 -Complex transaction processing.

Because vertical slicing distributes tables across different libraries according to business classification, some business tables can be too large and have single library read-write and storage bottlenecks, so horizontal splitting is required to resolve them.

  • horizontal partitioning

In contrast to vertical splitting, horizontal splitting does not categorize tables, but spreads them across libraries according to some rule of a field, each containing a portion of the data.Simply put, we can think of horizontal slicing of data as slicing by rows of data, that is, slicing some rows of a table into one database, and some rows into other databases, as shown in the following figure:

    ! [Insert picture description here] (https://img-blog.csdnimg.cn/20190804210504414.png)
** Advantages: **
 -The splitting rules are abstract and the join operation can be basically done by the database;
 - There is no single library of large data, high concurrent performance bottleneck;
 - Fewer modifications on the application side;
 -Improves system stability and load capacity.
**Disadvantages:**
 -Split rules are difficult to abstract;
 - Fragmented transaction consistency is difficult to resolve;
 - The difficulty of multiple data expansion and the amount of maintenance are enormous;
 -Split rules are difficult to abstract;
 - Fragmented transaction consistency is difficult to resolve;

And so on.Specifically, refer to Mycat's problem description.There are also slicing strategies supported by Mycat:
http://www.mycat.io/document/...

Using Enumerated Partitioning Algorithm to Implement Library Based on Mycat

Create three databases

Modify the configuration file, and if you find it slow to enter manually, copy it directly and then modify the library name and connection information

schema.xml To configure

<mycat:schema xmlns:mycat="http://io.mycat/">
    <!-- testdb yes mycat The name of the logical library for the link -->
    <schema name="testdb" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1">
       <!--rule Corresponding rule.xml name Name of -->
      <table name="t_user"  dataNode="dn1,dn2,dn3" rule="role2" /> 
    
    </schema>
        <!-- database yes MySQL The name of the database -->
    <dataNode name="dn1" dataHost="localhost1" database="t_user1" />
    <dataNode name="dn2" dataHost="localhost1" database="t_user2" />
    <dataNode name="dn3" dataHost="localhost1" database="t_user3" />

     <dataHost name="localhost1" maxCon="1000" minCon="10" balance="3" writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
        <heartbeat>select user()</heartbeat>
        <!-- Multiple master-slaves can be configured -->
        <writeHost host="hostM1" url="192.168.100.131:3306" user="root" password="root">
            <!-- Multiple slave libraries can be configured -->
            <readHost host="hostS2" url="192.168.100.132:3306" user="root" password="root" />
        </writeHost>
    </dataHost>
</mycat:schema>

rule.xml To configure

<mycat:rule xmlns:mycat="http://io.mycat/">
    <tableRule name="role2">
             <rule>
             <!-- According to the incoming name Field to determine which library to store -->
                  <columns>name</columns>
                  <!-- Specified Rules -->
                <algorithm>hash-int</algorithm>
                </rule>
    </tableRule> 
    <function name="hash-int" class="io.mycat.route.function.PartitionByFileMap">
    <!-- Specified Rule Enumeration File -->
        <property name="mapFile">partition-hash-int.txt</property>
        <!-- key Write 0 if it is a numeric value, not 1 -->
        <property name="type">1</property>
        <!-- If none of them match, default save in 1 node Library -->
        <property name="defaultNode">1</property>
    </function>
</mycat:rule>

partition-hash-int.txt To configure   key yes name Corresponding values, value Refers to which library exists
hefei=0
nanjing=1
bengbu=2

server.xml To configure
<mycat:server xmlns:mycat="http://io.mycat/">
   <!-- Read and Write Available Users -->
    <user name="root" defaultAccount="true">
        <property name="password">root</property>
        <property name="schemas">testdb</property>
    </user>
    <!-- Read-Only User -->
    <user name="user">
        <property name="password">user</property>
        <property name="schemas">testdb</property>
        <property name="readOnly">true</property>
    </user>
</mycat:server>

This completes the configuration and starts Mycat.Why tables are not found when using Navicat connections

From the log, you can see that each time you query a table, you carry the name of the logical library.As a result, no queries were made.I have not solved the problem yet.Queries and additions can only be made by writing sql.


Four New District names

INSERT INTO t_user (name) VALUES ('shanghai');
INSERT INTO t_user (name) VALUES ('nanjing');
INSERT INTO t_user (name) VALUES ('hefei');
INSERT INTO t_user (name) VALUES ('bengbu');


So you can see the effect

There are also many fragmentation strategies that can be seen in the official Macat guide.
http://www.mycat.io/document/...

Keywords: Java mycat Database xml MySQL

Added by kr3m3r on Sun, 08 Sep 2019 09:07:05 +0300