当前位置:   article > 正文

ruoyi-vue分离版3.8.3整合shardingsphere分库分表5.2.1_yamlshardingspheredatasourcefactory

yamlshardingspheredatasourcefactory

        本文介绍基于yaml配置文件的全配置分库分表引擎整合,无需java代码编写配置config,下载源代码目的是为了要里面的yaml配置文件,并不需要安装编译shardingsphere。

一、官网下载apache-shardingsphere-5.2.1-src.zip,里面的test项目下面有很多yaml配置文件可以参考。

二、更改ruoyi-admin下面的application-druid.yml并创建application-sharding.yml,在application-druid.yml最下面增加:

spring:
    datasource:

                。。。。。。(原有配置省略)

    shardingsphere:
        configLocation: application-sharding.yml

三、这是我的application-sharding.yml配置文件,请大家参考:

# 分库分表配置
dataSources:
  ds_0:
    dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
    driverClassName: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/ds_0?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
    username: root
    password: root
    maxTotal: 100
  ds_1:
    dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
    driverClassName: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/ds_1?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
    username: root
    password: root
    maxTotal: 100

rules:
  - !TRANSACTION
    defaultType: LOCAL
  - !SHARDING
    tables:
      tmp_order:
        actualDataNodes: ds_${0..1}.tmp_order_${0..1}
        tableStrategy:
          standard:
            shardingColumn: order_id
            shardingAlgorithmName: tmp_order_inline
        keyGenerateStrategy:
          column: order_id
          keyGeneratorName: snowflake
      tmp_order_item:
        actualDataNodes: ds_${0..1}.tmp_order_item_${0..1}
        tableStrategy:
          standard:
            shardingColumn: order_id
            shardingAlgorithmName: tmp_order_item_inline
        keyGenerateStrategy:
          column: order_item_id
          keyGeneratorName: snowflake
      sys_orde
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/757126
推荐阅读
相关标签
  

闽ICP备14008679号