Mycat distributed database architecture solution -- details of schema.xml

Echo editor, welcome to reprint, reprint please state the source of the article. Welcome to add echo wechat (wechat: t2421499075) for communication and learning Never lose in a hundred battles, never claim to win, never lose in a hundred defeats, and strive to move forward. ——This is really powerful!!!

This file is a system configuration information file containing MYCAT. The corresponding original code is SystemConfig.java. We will explain this file in detail. This file is in our installation package, / mycat/conf (this article is based on "MYCAT distributed database architecture solution -- Linux Installation and running MYCAT"). You can understand the directory structure after installation. If you want to compare the detailed configuration file, you can also directly download the MYCAT source code from github at the download address: https://github.com/MyCATApache/Mycat-Server

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

    <!-- schema Labels are mainly used to define Mycat The logical library in the instance. Mycat There can be multiple logical libraries, each with its own related configuration -->
    <!-- have access to schema Label to divide different logical Libraries,If not configured schema Label, all table configurations will belong to the same default logical library -->
    <!-- name="TESTDB" to Mycat Define logical library name -->
    <!-- checkSQLschema Attribute value is true When we execute a statement select * from TESTDB.table;This setting will talk about TESTDB Intercept, SQL Become select * from table;This rule can only be cut off schema Library specified on -->
    <!-- sqlMaxLimit When the property is set to 100, the SQL Statement if not added limit Sentence, Mycat Will automatically add limit 100;If it is not set, all the information queried will be returned -->
    <schema name="TESTDB" checkSQLschema="true" sqlMaxLimit="100">
        <!-- table The label defines Mycat All tables to be split need to be in the table Defined in the label.-->
        <!-- name Property defines the name of the logical table,The same schema Defined in the label table Name must be unique -->
        <!-- dataNode Property the value of this property needs to match the following dataNode Label name The values of the properties correspond to each other. If there are multiple values, use the','Separate -->
        <!-- rule Property is used to specify the rule to be used by the logical table. The name of the rule is defined in rule.xml Must be consistent with tableRule Label name Attribute consistency -->
        <!-- ruleRequired Property is used to specify whether the table binds sharding rules, if configured true,But there is no specific configuration rule,The program will report an error.-->
        <!-- primaryKey Property corresponds to the primary key of the real table -->
        <!-- type Attribute defines the type of logical table. At present, there are only two types of logical table: global table and common table. Configuration values corresponding to the global table: global,Do not specify normal table -->
        <!-- autoIncrement Attribute default false,Set to become true Time Mycat Use self growing primary keys for tables -->
        <!-- subTables Property at present Mycat At 1.6 Sub tables are supported only after version, and dataNode Only one can be configured under the table splitting condition. It does not support all conditions join Associated query statement -->
        <!-- needAddLimit Specifies whether the table needs to be automatically followed by each statement limit Restrictions. If set to true,Mycat Add it to us automatically when querying limit 100 -->
        <table name="travelrecord" needAddLimit="true" ruleRequired="true" autoIncrement="false" primaryKey="" dataNode="dn1,dn2,dn3" rule="auto-sharding-long"/>
    </schema>
    <!-- One schema Represents a logical library -->
    <schema name="TEST" checkSQLschema="true" sqlMaxLimit="100">
        <table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long"/>
    </schema>
    <!-- dataNode Property is used to bind a logical database to a specific database. Mycat1.3 If configured dataNode,The partition table cannot be configured;
    Mycat 1.4 And 1.5 The version can be configured with default sharding, and the tables that need to be sharded can be configured -->
    <!-- name Attribute corresponds to the above schema Middle DataNode Name -->
    <!-- database Property specifies the name of the real database -->
    <!-- dataHost Property is corresponding to database Mycat Logical library name -->
    <dataNode name="dn1" dataHost="Node1" database="db1"/>
    <dataNode name="dn2" dataHost="Node2" database="db2"/>
    <dataNode name="dn3" dataHost="Node3" database="db3"/>

    <!-- It is schema.xml Last label in,The label is in Mycat Logical database exists as the underlying tag, which directly defines the specific database instance, read-write separation and heartbeat statement.-->
    <!-- name Property is the unique identity dataHost Label, for upper label -->
    <!-- maxCon Property specifies the maximum number of connections per read-write instance connection pool. Embedded Tags writeHost/readHost The maximum number of connections in the connection pool will be instantiated using the value class of this property -->
    <!-- minCon Property specifies the minimum number of connections for each read-write instance connection pool, and initializes the size of the connection pool -->
    <!-- balance Attribute belongs to load balancing type. Currently, it has the following 4 median values
        balance="0" Do not turn on the read-write separation mechanism, all operations are sent to the currently available writeHost Up.
        balance="1" All-out readHost And stand by writeHost All involved select Statement load balancing.
        balance="2" All read operations are randomly writeHost,readHost Distribute on.
        balance="3" All read requests are randomly distributed to writeHost Corresponding readHost Perform on writeHost No reading pressure-->
    <!-- writeType Property has two values writeType="0" All writes are sent to the first configured writeHost Up, writeHost1 Cut to writeHost2 upper
         writeType="1" All writes are sent randomly to the configured writeHost upper -->
    <!-- dbType Property specifies the database type of the back-end connection. Currently, in addition to binary MySQL Protocol, also supports the use of JDBC Connected database,for example MongoDB.Oracle etc. -->
    <!-- daDriver Specifies the Driver,Currently available are native and JDBC -->
    <!-- switchType attribute
            switchType="-1"Indicates no automatic switching.
            switchType="1"Is the default value, indicating automatic switching.
            switchType="2"Based on MySQL The state of master-slave synchronization determines whether to switch.
            switchType="3"Based on MySQL Galary Cluster Switching mechanism of.-->
    <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0" writeType="0"
              dbType="mysql" tempReadHostAvailable="" dbDriver="native" switchType="1" slaveThreshold="100">
        <!-- heartbeat The tag indicates the statement used for heartbeat checking in the backend database,MySQL Use select user() Oracle Use select 1 from dual-->
        <heartbeat>select user()</heartbeat>
        <!-- writeHost Label and readHost Just like the label, it specifies Mycat Related configuration of back-end database, used to instantiate back-end connection pool. The only difference is, writeHost Specify the write instance, readHost Specify read instance -->
        <!-- host Property is used to represent different instances,about writeHost We usually use*M1;about readHost,We usually use*S1.  -->
        <!-- url attribute,Connection address of the connection backend instance -->
        <!-- user attribute,User name of the backend storage instance -->
        <!-- password attribute,Password for backend storage instance -->
        <!-- weight Attribute in readHost Weight as read node in -->
        <!-- usingDecrypt Same attribute server.mxl Medium usingDecrypt Configuration -->
        <writeHost host="hostM1" url="192.168.222.132:3306" user="root" password="123456"></writeHost>
    </dataHost>
</mycat:schema>

Be a blogger with a bottom line

Tags: Java mycat Database Attribute MySQL

Posted on Tue, 05 Nov 2019 11:18:59 -0500 by kemu_