Mycat configuration of schema.xml

As one of MyCat Schema.xml important configuration files, managing MyCat logical databases, tables, fragmentation rules, DataNode and DataSource.

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

        <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
                <!-- auto sharding by id (long) -->
                <table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" />

                <!-- global table is auto cloned to all defined data nodes ,so can join
                        with any table whose sharding node is in the same data node -->
                <table name="company" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" />
                <table name="goods" primaryKey="ID" type="global" dataNode="dn1,dn2" />
                <!-- random sharding using mod sharind rule -->
                <table name="hotnews" primaryKey="ID" autoIncrement="true" dataNode="dn1,dn2,dn3"
                           rule="mod-long" />
                <!-- <table name="dual" primaryKey="ID" dataNode="dnx,dnoracle2" type="global"
                        needAddLimit="false"/> <table name="worker" primaryKey="ID" dataNode="jdbc_dn1,jdbc_dn2,jdbc_dn3"
                        rule="mod-long" /> -->
                <table name="employee" primaryKey="ID" dataNode="dn1,dn2"
                           rule="sharding-by-intfile" />
                <table name="customer" primaryKey="ID" dataNode="dn1,dn2"
                           rule="sharding-by-intfile">
                        <childTable name="orders" primaryKey="ID" joinKey="customer_id"
                                                parentKey="id">
                                <childTable name="order_items" joinKey="order_id"
                                                        parentKey="id" />
                        </childTable>
                        <childTable name="customer_addr" primaryKey="ID" joinKey="customer_id"
                                                parentKey="id" />
                </table>
                <!-- <table name="oc_call" primaryKey="ID" dataNode="dn1$0-743" rule="latest-month-calldate"
                        /> -->
        </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:3306" user="root"
                                   password="123456">
                        <!-- can have multi read hosts -->
                        <readHost host="hostS2" url="192.168.1.200:3306" user="root" password="xxx" />
                </writeHost>
                <writeHost host="hostS1" url="localhost:3316" user="root"
                                   password="123456" />
                <! - <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
        </dataHost>
        <!--
                <dataHost name="sequoiadb1" maxCon="1000" minCon="1" balance="0" dbType="sequoiadb" dbDriver="jdbc">
                <heartbeat>             </heartbeat>
                 <writeHost host="hostM1" url="sequoiadb://1426587161.dbaas.sequoialab.net:11920/SAMPLE" user="jifeng"  password="jifeng"></writeHost>
                 </dataHost>

          <dataHost name="oracle1" maxCon="1000" minCon="1" balance="0" writeType="0"   dbType="oracle" dbDriver="jdbc"> <heartbeat>select 1 from dual</heartbeat>
                <connectionInitSql>alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'</connectionInitSql>
                <writeHost host="hostM1" url="jdbc:oracle:thin:@127.0.0.1:1521:nange" user="base"       password="123456" > </writeHost> </dataHost>

                <dataHost name="jdbchost" maxCon="1000"         minCon="1" balance="0" writeType="0" dbType="mongodb" dbDriver="jdbc">
                <heartbeat>select       user()</heartbeat>
                <writeHost host="hostM" url="mongodb://192.168.0.99/test" user="admin" password="123456" ></writeHost> </dataHost>

                <dataHost name="sparksql" maxCon="1000" minCon="1" balance="0" dbType="spark" dbDriver="jdbc">
                <heartbeat> </heartbeat>
                 <writeHost host="hostM1" url="jdbc:hive2://feng01:10000" user="jifeng"         password="jifeng"></writeHost> </dataHost> -->

        <!-- <dataHost name="jdbchost" maxCon="1000" minCon="10" balance="0" dbType="mysql"
                dbDriver="jdbc"> <heartbeat>select user()</heartbeat> <writeHost host="hostM1"
                url="jdbc:mysql://localhost:3306" user="root" password="123456"> </writeHost>
                </dataHost> -->
</mycat:schema>
View Code

A, <schema> tag

<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100"></schema>

The tag logic schema library definition myCat instance, there may be a plurality of logical myCat libraries, each logical bank has its own configuration. Schema tags may be used to divide the different logical bank.
If no schema tag, all table configuration, will belong to the same default logical library.

schema tag relevant attributes:

  • dataNode any String
  • checkSQLschema Boolean
  • sqlMaxLimit Integer

1. DataNode

Logic libraries for binding to a specific database.

2. checkSQLschema

When the value is set to true, if we execute the statement ** select * from TESTDB.travelrecord; ** the MyCat statement will modify the ** select * from travelrecord; **. That is, representing schema characters removed, to avoid sending the back-end database to perform Times ** (ERROR1146 (42S02): Table 'testdb.travelrecord' does not exist). **
providing SQL statement is best not to take this field.

3. sqlMaxLimit

When the value is set to a certain value. Each execution of SQL statements, if not coupled limit statement, MyCat will automatically add value corresponds. 100 is provided, for example, performs ** select * from TESTDB.travelrecord; ** effects and perform ** select * from TESTDB.travelrecord limit 100; ** the same
set, then the value, myCat will default to query all information They are displayed, resulting in excessive output. Therefore, in normal use, it is recommended to add a value for reducing the excess data is returned.
Of course, the size of the SQL statements also explicitly specify a limit, not bound by this property.
Note that, schema database if you are running a non-split, then the property will not take effect. Need to manually add limit statements.

Two, <table> tag

<table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" ></table>

Table MyCat tag defines the logic table, all the tables need to be split are placed into this tag.

table-related properties:

  • name String
  • dataNode String
  • rule String
  • ruleRequired boolean
  • primaryKey String
  • type String
  • autoIncrement boolean
  • subTables String
  • needAddLimit boolean

1. name attribute

Table name defined logic table, the name just as I execute create table command specifies the name of the database, as defined in the tag with a schema name must be unique.

2. dataNode property

The definition of a logical table belongs dataNode, and values ​​required Datanode label for the attribute value of the attribute name correspond to each other.

3. rule properties

Rules specify the logical name of the table to use, rule names defined in rule.xml must correspond with the name attribute value of the attribute tableRule tag.

4. ruleRequired Properties

Specify the table is bound fragmentation rules, if the configuration is true, but there is no specific rule configuration, the program will complain.

5. primaryKey Properties

Corresponding to the primary key of the real table, for example: Rule fragment using non-primary key to be fragmented, then at the time of using the primary key query, sends a query to all configurations the DN, if using the attribute configuration real table's primary key . name MyCat caches information about the primary key and specific DN, then when using non-primary key again query will not be broadcast queries will be sent direct statements to the specific DN, but although the configuration of the property, if the cache is not hit , then it would send statements to the specific DN, to obtain the data.

6. type property

It defines the type of logic table, the current logic table only "global" and the "ordinary form" of two types. Corresponding configuration:

  • Global table: global. --- If it is determined that the global table that each node has a slice, then use mycat login, and then build a unified table can be.
  • Ordinary table: the table is not specified all of globla.

7. autoIncrement property

mysql for non-self-growth primary key, use last_insert_id () does not return a result, it will only return 0. Therefore, only the definition of the table from the growth of the primary key can return to the main key with last_insert_id ().

mycat currently offers self-growth primary key function, but if the mysql node corresponding data table is not defined auto_increment, then call last_insert_id in mycat layer () is not returning results.

Use autoIncrement = "true" to specify the use of growth since the table has a primary key, the default is disabled.

8. subTables

Add subTables = "t_order $ 1-2, t_order3 " use.
Now beginning to support future Table 1.6 points and dataNode can only be configured in a sub-table conditions, various conditions are not supported under conditions of sub-table join statement.

9. needAddLimit Properties

Specifies whether the table needs to add automatic limit restrictions after each statement. The use of a sub-library sub-table, sometimes huge amounts of data. This time execute a query, if they happen to forget to add a limit to the number of words. All of the query data out enough to wait for a little while. So, mycat automatically as we add LIMIT 100. Of course, if there is limit statement, it would not be time added. This property defaults to true, you can also set out to false` disable the default behavior.

Three, <childTable> tag

a sub-tab table definition childTable ER fragment. It is associated with the parent table by attribute on the tag.

Tags related properties:

  • name String
  • joinKey String
  • parentKey String
  • primaryKey String
  • needAddLimit boolean

 

Guess you like

Origin www.cnblogs.com/myitnews/p/12380422.html