分庫分表 中間件 ShardingProxy

下載
https://dlcdn.apache.org/shardingsphere/5.5.1/apache-shardingsphere-5.5.1-shardingsphere-proxy-bin.tar.gz

apache-shardingsphere-5.5.1-shardingsphere-proxy-bin

將idea Maven下的 mysql-connector-java 包 復(fù)制到lib

 配置 

databaseName: SALESMANAGER

dataSources:
 ds_0:
   url: jdbc:mysql://192.168.1.103:3036/SALESMANAGER?useSSL=false
   username: root
   password: wusu1314
   connectionTimeoutMilliseconds: 30000
   idleTimeoutMilliseconds: 60000
   maxLifetimeMilliseconds: 1800000
   maxPoolSize: 50
   minPoolSize: 1
 ds_1:
   url: jdbc:mysql://192.168.1.103:3037/SALESMANAGER?useSSL=false
   username: root
   password: wusu1314
   connectionTimeoutMilliseconds: 30000
   idleTimeoutMilliseconds: 60000
   maxLifetimeMilliseconds: 1800000
   maxPoolSize: 50
   minPoolSize: 1

rules:
- !READWRITE_SPLITTING
 #讀寫分離
 dataSourceGroups:
   readwrite_ds:
     writeDataSourceName: ds_0
     readDataSourceNames: 
       - ds_1
      #  - read_ds_1
     loadBalancerName: random
 loadBalancers:
   random:
     type: RANDOM

- !SHARDING
#分庫分表
 tables:
   orders:
     actualDataNodes: ds_0.orders_${0..1}  #數(shù)據(jù)節(jié)點
     tableStrategy:
       standard:
         shardingColumn: ORDER_ID
         shardingAlgorithmName: t_order_inline  #算法分片
     keyGenerateStrategy: #密鑰生成策略
       column: ORDER_ID
       keyGeneratorName: snowflake #雪花算法
     auditStrategy:
       auditorNames:
         - sharding_key_required_auditor
       allowHintDisable: true
  #  product:
  #    actualDataNodes: ds_0.product_${0..1}
  #    tableStrategy:
  #      standard:
  #        shardingColumn: PRODUCT_ID
  #        shardingAlgorithmName: t_product_inline
  #    keyGenerateStrategy:
  #      column: PRODUCT_ID
  #      keyGeneratorName: snowflake
 bindingTables:
   - orders
 defaultTableStrategy:
   none:
 defaultAuditStrategy:
   auditorNames:
     - sharding_key_required_auditor
   allowHintDisable: true

 shardingAlgorithms:
   t_order_inline:
     type: INLINE
     props:
       algorithm-expression: orders_${ORDER_ID % 2}
  #  t_product_inline:
  #    type: INLINE
  #    props:
  #      algorithm-expression: product_${PRODUCT_ID % 2}

 keyGenerators:
   snowflake:
     type: SNOWFLAKE

 auditors:
   sharding_key_required_auditor:
     type: DML_SHARDING_CONDITIONS
- !SINGLE
  tables: 
    - "*.*"

以上為讀寫分離 +單庫分表
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容