栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

shardingsphere-jdbc

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

shardingsphere-jdbc

shardingsphere-jdbc有四个分片规则

使用

在springboot环境下使用

		
            org.apache.shardingsphere
            sharding-jdbc-spring-boot-starter
            4.1.1
        
        
            org.apache.shardingsphere
            sharding-transaction-xa-core
            4.1.1
        
        <还有Mybatis依赖>
配置
spring:
  main:
    allow-bean-definition-overriding: true
  shardingsphere:
    datasource:
      names: m1,m2 # 代表两个库
      m1:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-calss-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/mysql?characterEncoding=utf-8&useSSL=false&serverTimezone=Hongkong&allowPublicKeyRetrieval=true
        username: root
        password: MyNewPass4!
      m2:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-calss-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&useSSL=false&serverTimezone=Hongkong&allowPublicKeyRetrieval=true
        username: root
        password: MyNewPass4!
    sharding:
      tables:
        person:
          actual-data-nodes: m$->{1..2}.person
          key-generator:
            column: id
            type: SNOWFLAKE
            props:
              worker:
                id: 1
#          table-strategy:
#            inline:
#              sharding-column: id
#              algorithm-expression: person->{id%2+1}
          database-strategy:
#            inline:
#              sharding-column: id
#              algorithm-expression: m$->{id%2+1}
#            standard:
#              sharding-column: id
#              precise-algorithm-class-name: org.miao.algorithm.DataBaseStandardPrecise
#              range-algorithm-class-name: org.miao.algorithm.DataBaseStandardRange
#            complex:
#              sharding-column: id,name
#              algorithm-class-name: org.miao.algorithm.DataBaseComplex
            hint:
              algorithm-class-name: org.miao.algorithm.DataBaseHintStrategy
    props:
      sql:
        show: true
inline standard

通过自定义分片策略实现精确分片和范围分片

complex

通过多分片键实现精确分片

hint

强制分片,通过非SQL方式强制干预

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/930971.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号