国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項超值服

開通VIP
Mycat分庫分表

數(shù)據(jù)節(jié)點(diǎn)配置

[schema.xml]配置

 <dataNode name="dn1" dataHost="localhost1" database="db1"/> <dataNode name="dn2" dataHost="localhost1" database="db2"/> <dataNode name="dn3" dataHost="localhost1" database="db3"/>
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

把localhost1中的 db1-3 數(shù)據(jù)庫映射到mycat dn1-3 節(jié)點(diǎn)

mycat分片規(guī)則

  1. 規(guī)則種類,在rule.xml文件中

    <table name="t_config" primaryKey="id" dataNode="dn1,dn2" rule="規(guī)則名" />
    • 1
    • 1
    • sharding-by-intfile 分片枚舉
    • rule1 固定分片hash算法
    • auto-sharding-long 范圍約定
    • mod-long 取模
    • sharding-by-date 按日期(天)分片
    • ………….
  2. mycat全局表
    如果你的業(yè)務(wù)中有些數(shù)據(jù)類似于數(shù)據(jù)字典,比如配置文件的配置,常用業(yè)務(wù)的配置或者數(shù)據(jù)量不大很少變動的表,這些表往往不是特別大,而且大部分的業(yè)務(wù)場景都會用到,那么這種表適合于 Mycat全局表,無須對數(shù)據(jù)進(jìn)行切分,只要在所有的分片上保存一份數(shù)據(jù)即可,Mycat 在Join 操作中,業(yè)務(wù)表與全局表進(jìn)行Join聚合會優(yōu)先選擇相同分片內(nèi)的全局表join,避免跨庫 Join,在進(jìn)行數(shù)據(jù)插入操作時,mycat將把數(shù)據(jù)分發(fā)到全局表對應(yīng)的所有分片執(zhí)行,在進(jìn)行數(shù)據(jù)讀取時候?qū)S機(jī)獲取一個節(jié)點(diǎn)讀取數(shù)據(jù)。
    配置[schema.xml]

    <table name="t_config" primaryKey="id" type="global" dataNode="dn1,dn2" />
    • 1
    • 1
  3. ER分片表
    有一類業(yè)務(wù),例如訂單(order)跟訂單明細(xì)(order_detail),明細(xì)表會依賴于訂單,也就是說會存在表的主從關(guān)系,這類似業(yè)務(wù)的切分可以抽象出合適的切分規(guī)則,比如根據(jù)用戶 ID切分,其他相關(guān)的表都依賴于用戶ID,再或者根據(jù)訂單ID切分,總之部分業(yè)務(wù)總會可以抽象出父子關(guān)系的表。這類表適用于 ER分片表,子表的記錄與所關(guān)聯(lián)的父表記錄存放在同一個數(shù)據(jù)分片上,避免數(shù)據(jù) Join跨庫操作。
    以order與 order_detail例子為例,schema.xml中定義如下的分片配置,order,order_detail 根據(jù) order_id進(jìn)行數(shù)據(jù)切分,保證相同 order_id的數(shù)據(jù)分到同一個分片上,在進(jìn)行數(shù)據(jù)插入操作時,Mycat會獲取 order所在的分片,然后將 order_detail也插入到 order所在的分片。
    配置[schema.xml]

    <table name="t_order" primaryKey="id" dataNode="dn$1-3" rule="mod-long">   <childTable name="t_order_detail" primaryKey="id" joinKey="order_id" parentKey="id" /></table>
    • 1
    • 2
    • 3
    • 1
    • 2
    • 3
  4. 多對多關(guān)聯(lián)
    有一類業(yè)務(wù)場景是 “主表A+關(guān)系表+主表B”,舉例來說就是商戶會員+訂單+商戶,對應(yīng)這類業(yè)務(wù),如何
    切分? 從會員的角度,如果需要查詢會員購買的訂單,那按照會員進(jìn)行切分即可,但是如果要查詢商戶當(dāng)天售出的訂單,那又需要按照商戶做切分,可是如果既要按照會員又要按照商戶切分,幾乎是無法實現(xiàn),這類業(yè)務(wù)如何選擇切分規(guī)則非常難。目前還暫時無法很好支持這種模式下的3個表之間的關(guān)聯(lián)。目前總的原則是需要從業(yè)務(wù)角度來看,關(guān)系表更偏向哪個表,即“A的關(guān)系”還是“B的關(guān)系”,來決定關(guān)系表跟從那個方向存儲,未來 Mycat版本中將考慮將中間表進(jìn)行雙向復(fù)制,以實現(xiàn)從A-關(guān)系表 以及B-關(guān)系表的雙向關(guān)聯(lián)查詢。

自增主鍵使用

  1. mycat配置

    [schema.xml]

    <table name="t_order" primaryKey="id" autoIncrement="true" dataNode="dn$1-3" rule="mod-long">    <childTable name="t_order_detail" primaryKey="id" autoIncrement="true" joinKey="order_id" parentKey="id" /></table>
    • 1
    • 2
    • 3
    • 1
    • 2
    • 3

    [sequence_db_conf.properties]

    #TABLE=dataNodeT_ORDER_DETAIL=dn1T_ORDER=dn1
    • 1
    • 2
    • 3
    • 4
    • 5
    • 1
    • 2
    • 3
    • 4
    • 5

    [sequence_conf.properties]

    T_ORDER.CURID=0T_ORDER.MINID=1T_ORDER.MAXID=10000T_ORDER_DETAIL.CURID=0T_ORDER_DETAIL.MINID=1T_ORDER_DETAIL.MAXID=10000
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    CURID表示當(dāng)前ID值,MINID表示最小ID值,MAXID表示最大ID值

  2. 重啟mycat,執(zhí)行sql

    #創(chuàng)建數(shù)據(jù)庫create table t_order(id bigint not null auto_increment primary key,company varchar(255))AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;create table t_order_detail(id bigint not null auto_increment primary key,good varchar(255),order_id bigint,CONSTRAINT FK_ORDID11 FOREIGN KEY (ORDER_ID) REFERENCES T_ORDER (ID))AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;#插入數(shù)據(jù)insert into t_order(company) values('alibaba');insert into t_order(company) values('tencent');insert into t_order(company) values('baidu');insert into t_order_detail(good,order_id) values('aliyun',1);insert into t_order_detail(good,order_id) values('qq',2);   insert into t_order_detail(good,order_id) values('baiduyun',3);
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

  3. 結(jié)論
    登陸MySQL查看db1-3的記錄,可以發(fā)現(xiàn),三條order記錄在不同db上,order_detail的記錄與所關(guān)聯(lián)的order表記錄存放在同一個數(shù)據(jù)分片上

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
MySQL分布式集群之MyCAT(二)schema詳解(修正)
myCat學(xué)習(xí)過程
Mycat全局表如何配置?mysql數(shù)據(jù)庫學(xué)習(xí)
開源數(shù)據(jù)庫中間件
數(shù)據(jù)庫中間件DBLE學(xué)習(xí)(二) 學(xué)習(xí)配置schema.xml
手摸手教你你用數(shù)據(jù)庫中間件Mycat SpringBoot完成分庫分表
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服