mycat之schema.xml理解

心已入冬 提交于 2021-02-03 13:34:19
<?xml version=\"1.0\"?>
    <!DOCTYPE mycat:schema SYSTEM \"schema.dtd\">
    <mycat:schema xmlns:mycat=\"http://org.opencloudb/\">

        <schema name=\"mycat\" checkSQLschema=\"false\" sqlMaxLimit=\"100\">
            <!-- auto sharding by id (long) -->
            <table name=\"students\" dataNode=\"dn1,dn2,dn3,dn4\" rule=\"rule1\" />
            <table name=\"log_test\" dataNode=\"dn1,dn2,dn3,dn4\" rule=\"rule2\" />
            <!-- 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\" />
                -->
            <table name=\"item_test\" primaryKey=\"ID\" type=\"global\" dataNode=\"dn1,dn2,dn3,dn4\" />
            <!-- random sharding using mod sharind rule -->
            <!-- <table name=\"hotnews\" primaryKey=\"ID\" dataNode=\"dn1,dn2,dn3\"
                rule=\"mod-long\" /> -->
                <!--
            <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\" />
                <ildTable>
                <childTable name=\"customer_addr\" primaryKey=\"ID\" joinKey=\"customer_id\"
                    parentKey=\"id\" /> -->
        </schema>

        <!-- <dataNode name=\"dn\" dataHost=\"localhost\" database=\"test\" /> -->
        <dataNode name=\"dn1\" dataHost=\"localhost\" database=\"test1\" />
        <dataNode name=\"dn2\" dataHost=\"localhost\" database=\"test2\" />
        <dataNode name=\"dn3\" dataHost=\"localhost\" database=\"test3\" />
        <dataNode name=\"dn4\" dataHost=\"localhost\" database=\"test4\" />
        <!--
        <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=\"localhost\" maxCon=\"100\" minCon=\"10\" balance=\"1\"
            writeType=\"1\" dbType=\"mysql\" dbDriver=\"native\">
            <heartbeat>select user()<beat>
            <!-- can have multi write hosts -->
            <writeHost host=\"localhost\" url=\"localhost:3306\" user=\"root\" password=\"wangwenan\">
                <!-- can have multi read hosts -->
                <readHost host=\"hostS1\" url=\"localhost:3307\" user=\"root\" password=\"wangwenan\"/>
            </writeHost>
            <writeHost host=\"localhost1\" url=\"localhost:3308\" user=\"root\" password=\"wangwenan\">
                <!-- can have multi read hosts -->
                <readHost host=\"hostS11\" url=\"localhost:3309\" user=\"root\" password=\"wangwenan\"/>
            </writeHost>
        </dataHost>
            <!-- <writeHost host=\"hostM2\" url=\"localhost:3316\" user=\"root\" password=\"123456\"/> -->
        <!--
            <dataHost name=\"jdbchost\" maxCon=\"1000\" minCon=\"1\" balance=\"0\" writeType=\"0\" dbType=\"mongodb\" dbDriver=\"jdbc\">
            <heartbeat>select user()<beat>
            <writeHost host=\"hostM\" url=\"mongodb://192.168.0.99/test\" user=\"admin\" password=\"123456\" ></writeHost>
        </dataHost>    
        -->
         <!--
        <dataHost name=\"jdbchost\" maxCon=\"1000\" minCon=\"10\" balance=\"0\"
            dbType=\"mysql\" dbDriver=\"jdbc\">
            <heartbeat>select user()<beat>
            <writeHost host=\"hostM1\" url=\"jdbc:mysql://localhost:3306\"
                user=\"root\" password=\"123456\">
            </writeHost>
        </dataHost>
         -->
    </mycat:schema>

参考:这几篇文章还是写的不错,都是一个系列的

http://blog.itpub.net/29510932/viewspace-1664499/  基础讲解

http://blog.itpub.net/29510932/viewspace-1667814/  配置文件schema.xml讲解

http://blog.itpub.net/29510932/viewspace-1678591/  分表规则

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!