sharding.yml 1.42 KB
# !!!数据源名称要和动态数据源中配置的名称一致
databaseName: master

# 具体参看官网文档说明
dataSources:
  coupon_user_db_0:
    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
    driverClassName: com.mysql.jdbc.Driver
    jdbcUrl: jdbc:mysql://192.168.1.18:3306/ruoyi-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true
    username: root
    password: root

rules:
  - !SHARDING
    tables: # 数据分片规则配置
      coupon_user: # 逻辑表名称
        actualDataNodes: coupon_user_db_0.coupon_user_$->{0..9} # 由数据源名 + 表名组成(参考 Inline 语法规则)
        databaseStrategy: # 分库策略,缺省表示使用默认分库策略,以下的分片策略只能选其一
          none:
        tableStrategy: # 分表策略
          standard: # 用于单分片键的标准分片场景
            shardingColumn: user_id # 分片列名称
            shardingAlgorithmName: user_inline
        keyGenerateStrategy:
          column: id
          keyGeneratorName: snowflake
    keyGenerators:
      snowflake:
        type: SNOWFLAKE
        props:
          worker-id: 123
    # 分片算法配置
    shardingAlgorithms:
      user_inline:
        type: INLINE
        props:
          algorithm-expression: coupon_user_$->{user_id % 10}

props:
  sql-show: true