码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2020-02-29 18:48:39      阅读:442      评论:0      收藏:0      [点我收藏+]

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

如题

采用了shardingSphere后,分库策略,分表策略都可以灵活使用了。

反过来会遇到一个新的问题,比如有个表不需要分库,也不需要分表,那么该怎么处理呢?

这里就要ShardingStrategy中的none配置了。

下面把配置贴出来:见配置中红色字体

关键点:

   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   

原文地址:https://www.cnblogs.com/chongpf/p/12384495.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!