分库分表 中间件 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 包 复制到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}  #数据节点
     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: 
    - "*.*"

以上为读写分离 +单库分表
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容