报错: schema DEMO,demo522_sub1 refered by user root is not exist!

报错: schema DEMO,demo522_sub1 refered by user root is not exist!

问题描述:

报错: schema DEMO,demo522_sub1 refered by user root is not exist!在navicat中A1,B1节点创建了这两个数据库,对比了schema.xml与server.xml,没找到问题,百度有人说可能要大写,我还没试(课程没强调要大写,而且有数字),该怎么解决这个问题呢

相关代码:

	<user name="root" defaultAccount="true">
		<property name="password">abc123456</property>
		<property name="schemas">DEMO,demo522_sub1,demo522_sub2</property>
		<property name="defaultSchema">DEMO</property>
		<!--No MyCAT Database selected 错误前会尝试使用该schema作为schema,不设置则为null,报错 -->
		
		<!-- 表级 DML 权限设置 -->
		<!-- 		
		<privileges check="false">
			<schema name="DEMO" dml="0110" >
				<table name="tb01" dml="0000"></table>
				<table name="tb02" dml="1111"></table>
			</schema>
		</privileges>		
		 -->
	</user>

	<user name="user">
		<property name="password">user</property>
		<property name="schemas">DEMO,demo522_sub1,demo522_sub2</property>
		<property name="readOnly">true</property>
		<property name="defaultSchema">DEMO</property>
	</user>

相关代码:

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
    <!--配置路由逻辑库可以向哪些数据表转发SQL语句-->
    <schema name="DEMO" checkSQLschema="true" sqlMaxLimit="100" randomDataNode="dn1">
        <table name="tb_emp" primaryKey="id" dataNode="dn1,dn2" type="global"/>
        <table name="tb_customer" primaryKey="id" dataNode="dn1,dn2" rule="mod-long" autoIncrement="true">
            <childTable name="tb_order" primaryKey="id" joinKey="customer_id" parentKey="id" autoIncrement="true"/>
        </table>
        <table name="tb_checkin" primaryKey="id" dataNode="dn1,dn2" rule="tb_checkin.range_rule"/>
        <table name="tb_coupon" primaryKey="id" dataNode="dn1,dn2" rule="tb_coupon_rule"/>
        <table name="tb_driver" primaryKey="id" dataNode="dn1,dn2" rule="city_rule"/>
        <table name="tb_leave" primaryKey="id" dataNode="dn1,dn2" rule="10day_rule"/>
    </schema>
    <schema name="demo522_sub1" checkSQLschema="true" sqlMaxLimit="100" randomDataNode="sub1_dn1">
        <table name="undo_log" primaryKey="id" dataNode="sub1_dn1,sub1_dn2" type="global"/>
        <table name="tb_student" primaryKey="id" dataNode="sub1_dn1,sub1_dn2" rule="mod-long" autoIncrement="true"/>
    </schema>
    <schema name="demo522_sub2" checkSQLschema="true" sqlMaxLimit="100" randomDataNode="sub2_dn1">
        <table name="undo_log" primaryKey="id" dataNode="sub2_dn1,sub2_dn2" type="global"/>
        <table name="tb_card" primaryKey="id" dataNode="sub2_dn1,sub2_dn2" rule="mod-long" autoIncrement="true"/>
    </schema>

    <!--使用A分片数据源中的哪个逻辑库-->
    <dataNode name="dn1" dataHost="A" database="DEMO" />
    <!--使用B分片数据源中的哪个逻辑库-->
    <dataNode name="dn2" dataHost="B" database="DEMO" />

    <dataNode name="sub1_dn1" dataHost="A" database="demo522_sub1" />
    <dataNode name="sub1_dn2" dataHost="B" database="demo522_sub1" />
    <dataNode name="sub2_dn1" dataHost="A" database="demo522_sub2" />
    <dataNode name="sub2_dn2" dataHost="B" database="demo522_sub2" />

    <!--配置A分片的数据源连接-->
    <dataHost name="A" maxCon="1000" minCon="10" balance="1" writeType="0" 
              dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
        <heartbeat>select 1</heartbeat>
        <writeHost host="w1" url="172.18.0.7:3306" user="root" password="abc123456">
            <readHost host="w1r1" url="172.18.0.8:3306" user="root" password="abc123456"/>
            <readHost host="w1r2" url="172.18.0.9:3306" user="root" password="abc123456"/>
        </writeHost>
        <writeHost host="w2" url="172.18.0.10:3306" user="root" password="abc123456">
            <readHost host="w2r1" url="172.18.0.11:3306" user="root" password="abc123456"/>
            <readHost host="w2r2" url="172.18.0.12:3306" user="root" password="abc123456"/>
        </writeHost>
    </dataHost>

    <!--配置B分片的数据源连接-->
    <dataHost name="B" maxCon="1000" minCon="10" balance="1" writeType="0" 
              dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
        <heartbeat>select 1</heartbeat>
        <writeHost host="w1" url="172.18.0.13:3306" user="root" password="abc123456">
            <readHost host="w1r1" url="172.18.0.14:3306" user="root" password="abc123456"/>
            <readHost host="w1r2" url="172.18.0.15:3306" user="root" password="abc123456"/>
        </writeHost>
        <writeHost host="w2" url="172.18.0.16:3306" user="root" password="abc123456">
            <readHost host="w2r1" url="172.18.0.17:3306" user="root" password="abc123456"/>
            <readHost host="w2r2" url="172.18.0.18:3306" user="root" password="abc123456"/>
        </writeHost>
    </dataHost>

</mycat:schema>

相关截图:

图片描述

相关截图:

图片描述

相关截图:

图片描述

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕小蓝 2024-11-01 09:38:34

同学你好,从报错信息看,是尝试使用root访问demo522_sub1时,这个数据库不存在,猜测确实可能是因为数据库名没有大写的问题。同学可以试一下。

另外,最好检查一下root用户确实对这个数据库有访问权限。

祝学习愉快~

  • 提问者 慕桂英5534918 #1

    检查了root对demo522_sub1访问权限,应该可以访问

    https://img1.sycdn.imooc.com/climg/67244867095fe13d25561527.jpg

    在配置文件中奖=将数据库名改成大写,仍然报这个错误,该怎么解决呢?

    <?xml version="1.0" encoding="UTF-8"?>

    <!-- - - Licensed under the Apache License, Version 2.0 (the "License"); 

    - you may not use this file except in compliance with the License. - You 

    may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 

    - - Unless required by applicable law or agreed to in writing, software - 

    distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 

    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 

    License for the specific language governing permissions and - limitations 

    under the License. -->

    <!DOCTYPE mycat:server SYSTEM "server.dtd">

    <mycat:server xmlns:mycat="http://io.mycat/">

    <system>

    <property name="nonePasswordLogin">0</property> <!-- 0为需要密码登陆、1为不需要密码登陆 ,默认为0,设置为1则需要指定默认账户-->

    <property name="ignoreUnknownCommand">0</property><!-- 0遇上没有实现的报文(Unknown command:),就会报错、1为忽略该报文,返回ok报文。

    在某些mysql客户端存在客户端已经登录的时候还会继续发送登录报文,mycat会报错,该设置可以绕过这个错误-->

    <property name="useHandshakeV10">1</property>

        <property name="removeGraveAccent">1</property>

    <property name="useSqlStat">0</property>  <!-- 1为开启实时统计、0为关闭 -->

    <property name="useGlobleTableCheck">0</property>  <!-- 1为开启全加班一致性检测、0为关闭 -->

    <property name="sqlExecuteTimeout">300</property>  <!-- SQL 执行超时 单位:秒-->

    <property name="sequnceHandlerType">2</property>

    <!--<property name="sequnceHandlerPattern">(?:(\s*next\s+value\s+for\s*MYCATSEQ_(\w+))(,|\)|\s)*)+</property>

    INSERT INTO `travelrecord` (`id`,user_id) VALUES ('next value for MYCATSEQ_GLOBAL',"xxx");

    -->

    <!--必须带有MYCATSEQ_或者 mycatseq_进入序列匹配流程 注意MYCATSEQ_有空格的情况-->

    <property name="sequnceHandlerPattern">(?:(\s*next\s+value\s+for\s*MYCATSEQ_(\w+))(,|\)|\s)*)+</property>

    <property name="subqueryRelationshipCheck">false</property> <!-- 子查询中存在关联查询的情况下,检查关联字段中是否有分片字段 .默认 false -->

    <property name="sequenceHanlderClass">io.mycat.route.sequence.handler.HttpIncrSequenceHandler</property>

          <!--  <property name="useCompression">1</property>--> <!--1为开启mysql压缩协议-->

            <!--  <property name="fakeMySQLVersion">5.6.20</property>--> <!--设置模拟的MySQL版本号-->

    <!-- <property name="processorBufferChunk">40960</property> -->

    <!-- 

    <property name="processors">1</property> 

    <property name="processorExecutor">32</property> 

    -->

            <!--默认为type 0: DirectByteBufferPool | type 1 ByteBufferArena | type 2 NettyBufferPool -->

    <property name="processorBufferPoolType">0</property>

    <!--默认是65535 64K 用于sql解析时最大文本长度 -->

    <!--<property name="maxStringLiteralLength">65535</property>-->

    <!--<property name="sequnceHandlerType">0</property>-->

    <!--<property name="backSocketNoDelay">1</property>-->

    <!--<property name="frontSocketNoDelay">1</property>-->

    <!--<property name="processorExecutor">16</property>-->

    <!--

    <property name="serverPort">8066</property> <property name="managerPort">9066</property> 

    <property name="idleTimeout">300000</property> <property name="bindIp">0.0.0.0</property>

    <property name="dataNodeIdleCheckPeriod">300000</property> 5 * 60 * 1000L; //连接空闲检查

    <property name="frontWriteQueueSize">4096</property> <property name="processors">32</property> -->

    <!--分布式事务开关,0为不过滤分布式事务,1为过滤分布式事务(如果分布式事务内只涉及全局表,则不过滤),2为不过滤分布式事务,但是记录分布式事务日志-->

    <property name="handleDistributedTransactions">0</property>

    <!--

    off heap for merge/order/group/limit      1开启   0关闭

    -->

    <property name="useOffHeapForMerge">0</property>


    <!--

    单位为m

    -->

            <property name="memoryPageSize">64k</property>


    <!--

    单位为k

    -->

    <property name="spillsFileBufferSize">1k</property>


    <property name="useStreamOutput">0</property>


    <!--

    单位为m

    -->

    <property name="systemReserveMemorySize">384m</property>



    <!--是否采用zookeeper协调切换  -->

    <property name="useZKSwitch">false</property>


    <!-- XA Recovery Log日志路径 -->

    <!--<property name="XARecoveryLogBaseDir">./</property>-->


    <!-- XA Recovery Log日志名称 -->

    <!--<property name="XARecoveryLogBaseName">tmlog</property>-->

    <!--如果为 true的话 严格遵守隔离级别,不会在仅仅只有select语句的时候在事务中切换连接-->

    <property name="strictTxIsolation">false</property>

    <property name="useZKSwitch">true</property>

    <!--如果为0的话,涉及多个DataNode的catlet任务不会跨线程执行-->

    <property name="parallExecute">0</property>

    </system>

    <!-- 全局SQL防火墙设置 -->

    <!--白名单可以使用通配符%或着*-->

    <!--例如<host host="127.0.0.*" user="root"/>-->

    <!--例如<host host="127.0.*" user="root"/>-->

    <!--例如<host host="127.*" user="root"/>-->

    <!--例如<host host="1*7.*" user="root"/>-->

    <!--这些配置情况下对于127.0.0.1都能以root账户登录-->

    <!--

    <firewall>

       <whitehost>

          <host host="1*7.0.0.*" user="root"/>

       </whitehost>

           <blacklist check="false">

           </blacklist>

    </firewall>

    -->


    <user name="root" defaultAccount="true">

    <property name="password">abc123456</property>

    <property name="schemas">DEMO,DEMO522_SUB1,DEMO522_SUB2</property>

    <property name="defaultSchema">DEMO</property>

    <!--No MyCAT Database selected 错误前会尝试使用该schema作为schema,不设置则为null,报错 -->

    <!-- 表级 DML 权限设置 -->

    <!--

    <privileges check="false">

    <schema name="DEMO" dml="0110" >

    <table name="tb01" dml="0000"></table>

    <table name="tb02" dml="1111"></table>

    </schema>

    </privileges>

    -->

    </user>


    <user name="user">

    <property name="password">user</property>

    <property name="schemas">DEMO,DEMO522_SUB1,DEMO522_SUB2</property>

    <property name="readOnly">true</property>

    <property name="defaultSchema">DEMO</property>

    </user>


    </mycat:server>









    <?xml version="1.0"?>

    <!DOCTYPE mycat:schema SYSTEM "schema.dtd">

    <mycat:schema xmlns:mycat="http://io.mycat/">

        <!--配置路由逻辑库可以向哪些数据表转发SQL语句-->

        <schema name="DEMO" checkSQLschema="true" sqlMaxLimit="100" randomDataNode="dn1">

            <table name="tb_emp" primaryKey="id" dataNode="dn1,dn2" type="global"/>

            <table name="tb_customer" primaryKey="id" dataNode="dn1,dn2" rule="mod-long" autoIncrement="true">

                <childTable name="tb_order" primaryKey="id" joinKey="customer_id" parentKey="id" autoIncrement="true"/>

            </table>

            <table name="tb_checkin" primaryKey="id" dataNode="dn1,dn2" rule="tb_checkin.range_rule"/>

            <table name="tb_coupon" primaryKey="id" dataNode="dn1,dn2" rule="tb_coupon_rule"/>

            <table name="tb_driver" primaryKey="id" dataNode="dn1,dn2" rule="city_rule"/>

            <table name="tb_leave" primaryKey="id" dataNode="dn1,dn2" rule="10day_rule"/>

        </schema>

        <schema name="DEMO522_SUB1" checkSQLschema="true" sqlMaxLimit="100" randomDataNode="sub1_dn1">

            <table name="undo_log" primaryKey="id" dataNode="sub1_dn1,sub1_dn2" type="global"/>

            <table name="tb_student" primaryKey="id" dataNode="sub1_dn1,sub1_dn2" rule="mod-long" autoIncrement="true"/>

        </schema>

        <schema name="DEMO522_SUB2" checkSQLschema="true" sqlMaxLimit="100" randomDataNode="sub2_dn1">

            <table name="undo_log" primaryKey="id" dataNode="sub2_dn1,sub2_dn2" type="global"/>

            <table name="tb_card" primaryKey="id" dataNode="sub2_dn1,sub2_dn2" rule="mod-long" autoIncrement="true"/>

        </schema>


        <!--使用A分片数据源中的哪个逻辑库-->

        <dataNode name="dn1" dataHost="A" database="DEMO" />

        <!--使用B分片数据源中的哪个逻辑库-->

        <dataNode name="dn2" dataHost="B" database="DEMO" />


        <dataNode name="sub1_dn1" dataHost="A" database="DEMO522_SUB1" />

        <dataNode name="sub1_dn2" dataHost="B" database="DEMO522_SUB1" />

        <dataNode name="sub2_dn1" dataHost="A" database="DEMO522_SUB2" />

        <dataNode name="sub2_dn2" dataHost="B" database="DEMO522_SUB2" />


        <!--配置A分片的数据源连接-->

        <dataHost name="A" maxCon="1000" minCon="10" balance="1" writeType="0" 

                  dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">

            <heartbeat>select 1</heartbeat>

            <writeHost host="w1" url="172.18.0.7:3306" user="root" password="abc123456">

                <readHost host="w1r1" url="172.18.0.8:3306" user="root" password="abc123456"/>

                <readHost host="w1r2" url="172.18.0.9:3306" user="root" password="abc123456"/>

            </writeHost>

            <writeHost host="w2" url="172.18.0.10:3306" user="root" password="abc123456">

                <readHost host="w2r1" url="172.18.0.11:3306" user="root" password="abc123456"/>

                <readHost host="w2r2" url="172.18.0.12:3306" user="root" password="abc123456"/>

            </writeHost>

        </dataHost>


        <!--配置B分片的数据源连接-->

        <dataHost name="B" maxCon="1000" minCon="10" balance="1" writeType="0" 

                  dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">

            <heartbeat>select 1</heartbeat>

            <writeHost host="w1" url="172.18.0.13:3306" user="root" password="abc123456">

                <readHost host="w1r1" url="172.18.0.14:3306" user="root" password="abc123456"/>

                <readHost host="w1r2" url="172.18.0.15:3306" user="root" password="abc123456"/>

            </writeHost>

            <writeHost host="w2" url="172.18.0.16:3306" user="root" password="abc123456">

                <readHost host="w2r1" url="172.18.0.17:3306" user="root" password="abc123456"/>

                <readHost host="w2r2" url="172.18.0.18:3306" user="root" password="abc123456"/>

            </writeHost>

        </dataHost>


    </mycat:schema>





    2024-11-01 11:21:21
  • 好帮手慕小蓝 回复 提问者 慕桂英5534918 #2

    同学你好,建议同学检查一下server.xml,将其中user账户的配置删除或者注释掉再试一下。

    祝学习愉快~

    2024-11-02 13:36:12
  • 提问者 慕桂英5534918 回复 好帮手慕小蓝 #3

    注释了,还是不行。老师,我知道您比较忙,但能尽快帮我解决这个问题吗?有点急,谢谢。

    https://img1.sycdn.imooc.com/climg/6725ce2109017b2c25591527.jpghttps://img1.sycdn.imooc.com/climg/6725ce6d09b9a68717201207.jpg


    <?xml version="1.0" encoding="UTF-8"?>

    <!-- - - Licensed under the Apache License, Version 2.0 (the "License"); 

    - you may not use this file except in compliance with the License. - You 

    may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 

    - - Unless required by applicable law or agreed to in writing, software - 

    distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 

    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 

    License for the specific language governing permissions and - limitations 

    under the License. -->

    <!DOCTYPE mycat:server SYSTEM "server.dtd">

    <mycat:server xmlns:mycat="http://io.mycat/">

    <system>

    <property name="nonePasswordLogin">0</property> <!-- 0为需要密码登陆、1为不需要密码登陆 ,默认为0,设置为1则需要指定默认账户-->

    <property name="ignoreUnknownCommand">0</property><!-- 0遇上没有实现的报文(Unknown command:),就会报错、1为忽略该报文,返回ok报文。

    在某些mysql客户端存在客户端已经登录的时候还会继续发送登录报文,mycat会报错,该设置可以绕过这个错误-->

    <property name="useHandshakeV10">1</property>

        <property name="removeGraveAccent">1</property>

    <property name="useSqlStat">0</property>  <!-- 1为开启实时统计、0为关闭 -->

    <property name="useGlobleTableCheck">0</property>  <!-- 1为开启全加班一致性检测、0为关闭 -->

    <property name="sqlExecuteTimeout">300</property>  <!-- SQL 执行超时 单位:秒-->

    <property name="sequnceHandlerType">2</property>

    <!--<property name="sequnceHandlerPattern">(?:(\s*next\s+value\s+for\s*MYCATSEQ_(\w+))(,|\)|\s)*)+</property>

    INSERT INTO `travelrecord` (`id`,user_id) VALUES ('next value for MYCATSEQ_GLOBAL',"xxx");

    -->

    <!--必须带有MYCATSEQ_或者 mycatseq_进入序列匹配流程 注意MYCATSEQ_有空格的情况-->

    <property name="sequnceHandlerPattern">(?:(\s*next\s+value\s+for\s*MYCATSEQ_(\w+))(,|\)|\s)*)+</property>

    <property name="subqueryRelationshipCheck">false</property> <!-- 子查询中存在关联查询的情况下,检查关联字段中是否有分片字段 .默认 false -->

    <property name="sequenceHanlderClass">io.mycat.route.sequence.handler.HttpIncrSequenceHandler</property>

          <!--  <property name="useCompression">1</property>--> <!--1为开启mysql压缩协议-->

            <!--  <property name="fakeMySQLVersion">5.6.20</property>--> <!--设置模拟的MySQL版本号-->

    <!-- <property name="processorBufferChunk">40960</property> -->

    <!-- 

    <property name="processors">1</property> 

    <property name="processorExecutor">32</property> 

    -->

            <!--默认为type 0: DirectByteBufferPool | type 1 ByteBufferArena | type 2 NettyBufferPool -->

    <property name="processorBufferPoolType">0</property>

    <!--默认是65535 64K 用于sql解析时最大文本长度 -->

    <!--<property name="maxStringLiteralLength">65535</property>-->

    <!--<property name="sequnceHandlerType">0</property>-->

    <!--<property name="backSocketNoDelay">1</property>-->

    <!--<property name="frontSocketNoDelay">1</property>-->

    <!--<property name="processorExecutor">16</property>-->

    <!--

    <property name="serverPort">8066</property> <property name="managerPort">9066</property> 

    <property name="idleTimeout">300000</property> <property name="bindIp">0.0.0.0</property>

    <property name="dataNodeIdleCheckPeriod">300000</property> 5 * 60 * 1000L; //连接空闲检查

    <property name="frontWriteQueueSize">4096</property> <property name="processors">32</property> -->

    <!--分布式事务开关,0为不过滤分布式事务,1为过滤分布式事务(如果分布式事务内只涉及全局表,则不过滤),2为不过滤分布式事务,但是记录分布式事务日志-->

    <property name="handleDistributedTransactions">0</property>

    <!--

    off heap for merge/order/group/limit      1开启   0关闭

    -->

    <property name="useOffHeapForMerge">0</property>


    <!--

    单位为m

    -->

            <property name="memoryPageSize">64k</property>


    <!--

    单位为k

    -->

    <property name="spillsFileBufferSize">1k</property>


    <property name="useStreamOutput">0</property>


    <!--

    单位为m

    -->

    <property name="systemReserveMemorySize">384m</property>



    <!--是否采用zookeeper协调切换  -->

    <property name="useZKSwitch">false</property>


    <!-- XA Recovery Log日志路径 -->

    <!--<property name="XARecoveryLogBaseDir">./</property>-->


    <!-- XA Recovery Log日志名称 -->

    <!--<property name="XARecoveryLogBaseName">tmlog</property>-->

    <!--如果为 true的话 严格遵守隔离级别,不会在仅仅只有select语句的时候在事务中切换连接-->

    <property name="strictTxIsolation">false</property>

    <property name="useZKSwitch">true</property>

    <!--如果为0的话,涉及多个DataNode的catlet任务不会跨线程执行-->

    <property name="parallExecute">0</property>

    </system>

    <!-- 全局SQL防火墙设置 -->

    <!--白名单可以使用通配符%或着*-->

    <!--例如<host host="127.0.0.*" user="root"/>-->

    <!--例如<host host="127.0.*" user="root"/>-->

    <!--例如<host host="127.*" user="root"/>-->

    <!--例如<host host="1*7.*" user="root"/>-->

    <!--这些配置情况下对于127.0.0.1都能以root账户登录-->

    <!--

    <firewall>

       <whitehost>

          <host host="1*7.0.0.*" user="root"/>

       </whitehost>

           <blacklist check="false">

           </blacklist>

    </firewall>

    -->


    <user name="root" defaultAccount="true">

    <property name="password">abc123456</property>

    <property name="schemas">DEMO,DEMO522_SUB1,DEMO522_SUB2</property>

    <property name="defaultSchema">DEMO</property>

    <!--No MyCAT Database selected 错误前会尝试使用该schema作为schema,不设置则为null,报错 -->

    <!-- 表级 DML 权限设置 -->

    <!--

    <privileges check="false">

    <schema name="DEMO" dml="0110" >

    <table name="tb01" dml="0000"></table>

    <table name="tb02" dml="1111"></table>

    </schema>

    </privileges>

    -->

    </user>


    <!--

    <user name="user">

    <property name="password">user</property>

    <property name="schemas">DEMO,DEMO522_SUB1,DEMO522_SUB2</property>

    <property name="readOnly">true</property>

    <property name="defaultSchema">DEMO</property>

    </user>

    -->


    </mycat:server>





    <?xml version="1.0"?>

    <!DOCTYPE mycat:schema SYSTEM "schema.dtd">

    <mycat:schema xmlns:mycat="http://io.mycat/">

        <!--配置路由逻辑库可以向哪些数据表转发SQL语句-->

        <schema name="DEMO" checkSQLschema="true" sqlMaxLimit="100" randomDataNode="dn1">

            <table name="tb_emp" primaryKey="id" dataNode="dn1,dn2" type="global"/>

            <table name="tb_customer" primaryKey="id" dataNode="dn1,dn2" rule="mod-long" autoIncrement="true">

                <childTable name="tb_order" primaryKey="id" joinKey="customer_id" parentKey="id" autoIncrement="true"/>

            </table>

            <table name="tb_checkin" primaryKey="id" dataNode="dn1,dn2" rule="tb_checkin.range_rule"/>

            <table name="tb_coupon" primaryKey="id" dataNode="dn1,dn2" rule="tb_coupon_rule"/>

            <table name="tb_driver" primaryKey="id" dataNode="dn1,dn2" rule="city_rule"/>

            <table name="tb_leave" primaryKey="id" dataNode="dn1,dn2" rule="10day_rule"/>

        </schema>

        <schema name="DEMO522_SUB1" checkSQLschema="true" sqlMaxLimit="100" randomDataNode="sub1_dn1">

            <table name="undo_log" primaryKey="id" dataNode="sub1_dn1,sub1_dn2" type="global"/>

            <table name="tb_student" primaryKey="id" dataNode="sub1_dn1,sub1_dn2" rule="mod-long" autoIncrement="true"/>

        </schema>

        <schema name="DEMO522_SUB2" checkSQLschema="true" sqlMaxLimit="100" randomDataNode="sub2_dn1">

            <table name="undo_log" primaryKey="id" dataNode="sub2_dn1,sub2_dn2" type="global"/>

            <table name="tb_card" primaryKey="id" dataNode="sub2_dn1,sub2_dn2" rule="mod-long" autoIncrement="true"/>

        </schema>


        <!--使用A分片数据源中的哪个逻辑库-->

        <dataNode name="dn1" dataHost="A" database="DEMO" />

        <!--使用B分片数据源中的哪个逻辑库-->

        <dataNode name="dn2" dataHost="B" database="DEMO" />


        <dataNode name="sub1_dn1" dataHost="A" database="DEMO522_SUB1" />

        <dataNode name="sub1_dn2" dataHost="B" database="DEMO522_SUB1" />

        <dataNode name="sub2_dn1" dataHost="A" database="DEMO522_SUB2" />

        <dataNode name="sub2_dn2" dataHost="B" database="DEMO522_SUB2" />


        <!--配置A分片的数据源连接-->

        <dataHost name="A" maxCon="1000" minCon="10" balance="1" writeType="0" 

                  dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">

            <heartbeat>select 1</heartbeat>

            <writeHost host="w1" url="172.18.0.7:3306" user="root" password="abc123456">

                <readHost host="w1r1" url="172.18.0.8:3306" user="root" password="abc123456"/>

                <readHost host="w1r2" url="172.18.0.9:3306" user="root" password="abc123456"/>

            </writeHost>

            <writeHost host="w2" url="172.18.0.10:3306" user="root" password="abc123456">

                <readHost host="w2r1" url="172.18.0.11:3306" user="root" password="abc123456"/>

                <readHost host="w2r2" url="172.18.0.12:3306" user="root" password="abc123456"/>

            </writeHost>

        </dataHost>


        <!--配置B分片的数据源连接-->

        <dataHost name="B" maxCon="1000" minCon="10" balance="1" writeType="0" 

                  dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">

            <heartbeat>select 1</heartbeat>

            <writeHost host="w1" url="172.18.0.13:3306" user="root" password="abc123456">

                <readHost host="w1r1" url="172.18.0.14:3306" user="root" password="abc123456"/>

                <readHost host="w1r2" url="172.18.0.15:3306" user="root" password="abc123456"/>

            </writeHost>

            <writeHost host="w2" url="172.18.0.16:3306" user="root" password="abc123456">

                <readHost host="w2r1" url="172.18.0.17:3306" user="root" password="abc123456"/>

                <readHost host="w2r2" url="172.18.0.18:3306" user="root" password="abc123456"/>

            </writeHost>

        </dataHost>


    </mycat:schema>






    2024-11-02 15:24:32
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
Java工程师 2024版
  • 参与学习       2052    人
  • 提交作业       1500    份
  • 解答问题       1324    个

2024重磅革新,超百小时内容豪华升级,加速提升高级技能与高薪就业竞争力 课程紧贴企业最新人才需求,历经7年持续迭代,帮助万名学子入行转行 从零起点到高阶实战,学习路径稳健顺滑,成就从小白到工程师高薪

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师