学会数据库读写分离、分表分库——用Mycat,这一篇就够了!

学会数据库读写分离、分表分库——用Mycat,这一篇就够了!
https://blog.csdn.net/pingdouble/article/details/79412004


2.0 Mycat实现MySQL的分库分表、读写分离、主从复制
https://blog.csdn.net/u011418530/article/details/88283945

mysql复制--主从复制配置
https://blog.csdn.net/daicooper/article/details/79905660

 

____________________________________________________________

 

 

 

MyCAT全局序列号
https://www.cnblogs.com/ivictor/p/5235147.html


Mycat之数据库主键自增长(数据库增长的方式)-yellowcong
https://blog.csdn.net/yelllowcong/article/details/79073608

MyCat自增主键
https://blog.51cto.com/8757576/2054713


Mycat单库分表
https://www.jianshu.com/p/fc11d28c67dc

 

文看懂mycat配置--数据库的读写分离、分表分库
https://www.jumtu.com/post/2706.html

 

——————————————————————————————————————————————
mycat分库后查询异常问题
 
mycat插入正常,但是查询的时候,查询结果分别是两个分库的数量,有时候显示50000,有时候显示10.

原因:在schema.xml中对该表的配置内多个 type="global"的配置,type 该属性定义了逻辑表的类型,目前逻辑表只有全局表和普通表。

全局表: global 普通表:无  注:全局表查询任意节点,普通表查询所有节点效率低。

去掉这个属性,重启mycat,再次查询后正常。
——————————————————————————————————————————————
原文链接:https://blog.csdn.net/qq_20867981/article/details/89326198

——————————————————————————————————————————————

 

 

 

测试通过方案:

 

 

<?xml version="1.0"?>

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

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

 

<!--

1. MyCAT全局序列号

2. 如下方案

-->

 

<!-- 数据库配置,与server.xml中的数据库对应 -->

         <schema name="DemoDB" checkSQLschema="true" sqlMaxLimit="100">

                   <!-- auto sharding by id (long)  randomDataNode="dn1" -->

                   <!--splitTableNames 启用<table name 属性使用逗号分割配置多个表,即多个表使用这个配置

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

                   -->       

                   <!--

                   <table name="oc_call" primaryKey="ID" dataNode="dn1$0-743" rule="latest-month-calldate"

                   /> -->

                   <!--  type="global" 查询任意节点 ,没有查询所节点 -->

                   <!--

                   分库分表方式1

                   <table name="t_order_0" primaryKey="order_id" autoIncrement="true"  dataNode="dn1,dn2"  rule="newmod-long" />

             <table name="t_order_1" primaryKey="order_id" autoIncrement="true"  dataNode="dn1,dn2"  rule="newmod-long" />

                   <table name="t_order_item_0" primaryKey="order_item_id" autoIncrement="true"  dataNode="dn1,dn2"  rule="newmod-long" />

                   <table name="t_order_item_1" primaryKey="order_item_id" autoIncrement="true"  dataNode="dn1,dn2"  rule="newmod-long" />

                   -->

                   <!-- 单库分表方式2 -->

                   <table name="t_order" primaryKey="order_id" autoIncrement="true" subTables="t_order_$0-1" dataNode="dn1"  rule="newmod-long" />

                   <table name="t_order_item" primaryKey="order_item_id" autoIncrement="true" subTables="t_order_$0-1" dataNode="dn1"  rule="newmod-long" />

         </schema>

 

         <!-- 分片配置 -->

         <dataNode name="dn1" dataHost="DemoDB01" database="demo_ds_0" />

         <dataNode name="dn2" dataHost="DemoDB02" database="demo_ds_1" />

 

         <!-- 物理数据库配置 -->

    <dataHost name="DemoDB01" maxCon="1000" minCon="10" balance="3"  writeType="0" dbType="mysql" dbDriver="native">

        <heartbeat>select user();</heartbeat>

        <writeHost host="hostM1" url="10.102.16.36:3306" user="root" password="root"> 

                     <readHost host="hostM1-S" url="10.102.16.64:3306" user="sa" password="abcd1234"/>

        </writeHost>

    </dataHost>

         <!-- balance 0不开启读写分离 1全参与select均衡  2随机均衡 3.读取到readHost写入writeHost -->

    <dataHost name="DemoDB02" maxCon="1000" minCon="10" balance="3"  writeType="0" dbType="mysql" dbDriver="native">

        <heartbeat>select user();</heartbeat>

        <writeHost host="hostM2" url="10.102.16.36:3306" user="root" password="root"> 

                     <readHost host="hostM2-S" url="10.102.16.64:3306" user="sa" password="abcd1234"/>

        </writeHost>

    </dataHost>

</mycat:schema>

 

posted @ 2020-03-27 12:31  kelelipeng  阅读(282)  评论(0编辑  收藏  举报