shardingsphere的读写分离和分表设置

本篇内容主要讲解“shardingsphere的读写分离和分表设置”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“shardingsphere的读写分离和分表设置”吧!

创新互联主要从事成都网站设计、网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务垫江,十年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108

shardingsphere版本


            org.apache.shardingsphere
            sharding-jdbc-spring-boot-starter
            4.1.1
        

springboot yml配置

spring:
  shardingsphere:
    datasource:
      names: master,slave0
      master: #主库
        type: com.zaxxer.hikari.HikariDataSource
        driverClassName: com.MySQL.cj.jdbc.Driver
        jdbcUrl: jdbc:mysql://xxx.xxxx.xxxx:3432/test?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useLocalSessionState=true
        username: db_dev
        password: db_dev123
      slave0: #从库(读库)
        type: com.zaxxer.hikari.HikariDataSource
        driverClassName: com.mysql.cj.jdbc.Driver
        jdbcUrl: jdbc:mysql://xxxx.xxxx.xxxx.xxxx:3433/test?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useLocalSessionState=true
        username: db_dev
        password: db_dev123

    sharding: #分片设置
      tables:  #分表规则
        t_order: #要做分表的表名(或者叫表名前辍)
          actualDataNodes: ms.t_order$->{0..2}  # t_order0~2子表, 这里的ms是主从名: ms
          tableStrategy: #表分片设置
            inline:
              shardingColumn: customer_id #以此字段做为分片条件
              algorithmExpression: t_order$->{customer_id % 3}  #数据分配策略,这里考虑客户维度的数据分表
          keyGenerator:
            column: id
            type: SNOWFLAKE #雪花算法
      masterSlaveRules: #主从设置(读写设置)
        ms:  #主从名
          masterDataSourceName: master #主库
          slaveDataSourceNames: slave0  #从库列表
          loadBalanceAlgorithmType: round_robin  #主从轮询规则
    props:
      sql:
        show: true

参考文档

https://shardingsphere.apache.org/document/legacy/3.x/document/cn/manual/sharding-proxy/configuration/ https://www.cnblogs.com/qdhxhz/p/11656205.html https://www.jianshu.com/p/cb48ba2941cb

到此,相信大家对“shardingsphere的读写分离和分表设置”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


网页题目:shardingsphere的读写分离和分表设置
转载源于:http://azwzsj.com/article/gjcooh.html