当前位置:Gxlcms > 数据库问题 > ShardingJdbc:集成ShardingSphere后,像MasterDataTable这样不需要分库分表,该怎么实现的一个方案

ShardingJdbc:集成ShardingSphere后,像MasterDataTable这样不需要分库分表,该怎么实现的一个方案

时间:2021-07-01 10:21:17 帮助过:5人阅读

关键点:

   default-data-source-name设置为主库数据源

  actual-nodes:设置主库数据源和物理表名

  database-strategy:设置none

  table-strategy:设置none

sharding:
  jdbc:
    datasource:
      names: master0,master0salve0,master0slave1,master1,master1slave0,master1slave1
      master0:
        type: com.alibaba.druid.pool.DruidDataSource
        url: jdbc:mysql://localhost:3306/mcspcsharding0?useUnicode=true&character_set_server=utf8mb4&useSSL=false&serverTimezone=GMT%2B8
        username: root
        password: root
      master0salve0:
        type: com.alibaba.druid.pool.DruidDataSource
        url: jdbc:mysql://localhost:3306/mcspcsharding0s0?useUnicode=true&character_set_server=utf8mb4&useSSL=false&serverTimezone=GMT%2B8
        username: root
        password: root
      master0slave1:
        type: com.alibaba.druid.pool.DruidDataSource
        url: jdbc:mysql://localhost:3306/mcspcsharding0s1?useUnicode=true&character_set_server=utf8mb4&useSSL=false&serverTimezone=GMT%2B8
        username: root
        password: root
      master1:
        type: com.alibaba.druid.pool.DruidDataSource
        url: jdbc:mysql://localhost:3306/mcspcsharding1?useUnicode=true&character_set_server=utf8mb4&useSSL=false&serverTimezone=GMT%2B8
        username: root
        password: root
      master1slave0:
        type: com.alibaba.druid.pool.DruidDataSource
        url: jdbc:mysql://localhost:3306/mcspcsharding1s0?useUnicode=true&character_set_server=utf8mb4&useSSL=false&serverTimezone=GMT%2B8
        username: root
        password: root
      master1slave1:
        type: com.alibaba.druid.pool.DruidDataSource
        url: jdbc:mysql://localhost:3306/mcspcsharding1s1?useUnicode=true&character_set_server=utf8mb4&useSSL=false&serverTimezone=GMT%2B8
        username: root
        password: root
    config:
      sharding:
        tables:
          mc_member:
            actual-nodes: mcspcsharding$->{0..1}.mc_member$->{0..1}
            database-strategy:
              standard:
                sharding-column: gender
                precise-algorithm-class-name: com.chong.mcspcshardingdbtable.sharding.DbShardingAlgorithm
            table-strategy:
              complex:
                sharding-columns: id
                algorithm-class-name: com.chong.mcspcshardingdbtable.sharding.MemberTblComplexKeySharding
          mc_master: # 主数据放置表,无需分库分表
            actual-nodes: mcspcsharding0.mc_master  # 指定主库中唯一的表节点
            database-strategy:
              none: # 分片策略为none
                sharding-column: none  # 分片键为none
            table-strategy:
              none: # 分片策略为none
                sharding-column: none # 分片键为none
        binding-tables: mc_member,mc_master
        default-data-source-name: master0 # 库分片策略为none时一定要设置默认数据源,否则应用无法启动

        master-slave-rules:
          ms0:
            master-data-source-name: master0
            slave-data-source-names: master0salve0,master0slave1
          ms1:
            master-data-source-name: master1
            slave-data-source-names: master1slave0,master1slave1

      props:
        sql:
          show: true

 

ShardingJdbc:集成ShardingSphere后,像MasterDataTable这样不需要分库分表,该怎么实现的一个方案

标签:precise   slave   分表   amp   end   HERE   time   sql   rtb   

人气教程排行