首页 > 其他分享 >shardingsphere-jdbc

shardingsphere-jdbc

时间:2023-04-03 11:01:55浏览次数:40  
标签:jdbc shardingsphere ds0 datasource spring sharding dhs

shardingsphere-jdbc

5.1.1版本

<dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
            <version>5.1.1</version>
        </dependency>

#shardingsphere
#spring.shardingsphere.mode.type=memory
#spring.shardingsphere.props.sql-show=true
#spring.shardingsphere.enabled=true
#spring.shardingsphere.datasource.names=ds0
#spring.shardingsphere.datasource.ds0.type=com.zaxxer.hikari.HikariDataSource
#spring.shardingsphere.datasource.ds0.driver-class-name=com.mysql.cj.jdbc.Driver
#spring.shardingsphere.datasource.ds0.url=jdbc:mysql://${mysql.host}/atp_dhs?useSSL=false&serverTimezone=Asia/Shanghai&allowMultiQueries=true
#spring.shardingsphere.datasource.ds0.username=${mysql.username}
#spring.shardingsphere.datasource.ds0.password=${mysql.password}
#spring.shardingsphere.datasource.ds0.initial-size=10
#spring.shardingsphere.datasource.ds0.min-idle=10
#spring.shardingsphere.datasource.ds0.maxActive=1000
#spring.shardingsphere.datasource.ds0.maxWait=60000
#spring.shardingsphere.datasource.ds0.timeBetweenEvictionRunsMillis=60000
#spring.shardingsphere.datasource.ds0.minEvictableIdleTimeMillis=300000
#spring.shardingsphere.datasource.ds0.validationQuery=SELECT 1
#spring.shardingsphere.datasource.ds0.testWhileIdle=true
#spring.shardingsphere.datasource.ds0.testOnBorrow=false
#spring.shardingsphere.datasource.ds0.testOnReturn=false
#spring.shardingsphere.datasource.ds0.poolPreparedStatements=true
#spring.shardingsphere.datasource.ds0.maxPoolPreparedStatementPerConnectionSize=20
#spring.shardingsphere.datasource.ds0.filters=stat,wall,log4j2
##spring.shardingsphere.datasource.ds0.connectionProperties=druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
#
#
#spring.shardingsphere.rules.sharding.default-data-source-name=ds0
#spring.shardingsphere.rules.sharding.props.sql-show=true
#spring.shardingsphere.rules.sharding.binding-tables[0]=dhs_annotation_gt,device_alarm_record
#spring.shardingsphere.rules.sharding.tables.dhs_annotation_gt.actual-data-nodes=ds0.dhs_annotation_gt_$->{0..1}
#spring.shardingsphere.rules.sharding.tables.dhs_annotation_gt.table-strategy.standard.sharding-column=image_id
#spring.shardingsphere.rules.sharding.tables.dhs_annotation_gt.table-strategy.standard.sharding-algorithm-name=sharding-by-image_id
#spring.shardingsphere.rules.sharding.sharding-algorithms.sharding-by-image_id.type=INLINE
#spring.shardingsphere.rules.sharding.sharding-algorithms.sharding-by-image_id.props.algorithm-expression=dhs_annotation_gt_$->{image_id % 2}
#
#spring.shardingsphere.rules.sharding.tables.device_alarm_record.actual-data-nodes=ds0.device_alarm_record20$->{21..99}$->{1..12}
#spring.shardingsphere.rules.sharding.tables.device_alarm_record.table-strategy.standard.sharding-column=pass_month
#spring.shardingsphere.rules.sharding.tables.device_alarm_record.table-strategy.standard.sharding-algorithm-name=sharding-alarm-by-month

5.3.1版本

         <shardingsphere.version>5.3.1</shardingsphere.version>
        <snakeyaml.version>1.33</snakeyaml.version>
       
       <!--ShardingSphere-jdbc start-->
        <dependency>
            <groupId>org.yaml</groupId>
            <artifactId>snakeyaml</artifactId>
            <version>${snakeyaml.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-jdbc-core</artifactId>
            <version>${shardingsphere.version}</version>
        </dependency>
        <!--ShardingSphere-jdbc end-->
# 配置 DataSource Driver
spring.datasource.driver-class-name=org.apache.shardingsphere.driver.ShardingSphereDriver
spring.datasource.url=jdbc:shardingsphere:classpath:atp-dhs-shardingsphere.yaml
mode:
  type: Standalone

dataSources:
  ds_0:
    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
    driverClassName: com.mysql.cj.jdbc.Driver
    jdbcUrl: jdbc:mysql://172.16.XX.XX:3306/atp_dhs?useSSL=false&serverTimezone=Asia/Shanghai&allowMultiQueries=true
    username: root
    password: RFErCVzNafwMySOb
  ds_1:
    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
    driverClassName: com.mysql.jdbc.Driver
    jdbcUrl: jdbc:mysql://172.16.XX.XX:3306/atp_dhs?useSSL=false&serverTimezone=Asia/Shanghai&allowMultiQueries=true
    username: root
    password: RFErCVzNafwMySOb

rules:
  - !SHARDING
    tables:
      dhs_annotation_gt:
        actualDataNodes: ds_${0..1}.dhs_annotation_gt_${0..1}
        tableStrategy:
          standard:
            shardingColumn: image_id
            shardingAlgorithmName: dhs_annotation_gt_inline
        keyGenerateStrategy:
          column: image_id
          keyGeneratorName: snowflake
      dhs_annotation_pred:
        actualDataNodes: ds_${0..1}.dhs_annotation_pred_${0..1}
        tableStrategy:
          standard:
            shardingColumn: image_id
            shardingAlgorithmName: dhs_annotation_pred_inline
        keyGenerateStrategy:
          column: image_id
          keyGeneratorName: snowflake
      dhs_origin_annotation_pred:
        actualDataNodes: ds_${0..1}.dhs_origin_annotation_pred_${0..1}
        tableStrategy:
          standard:
            shardingColumn: image_id
            shardingAlgorithmName: dhs_origin_annotation_pred_inline
        keyGenerateStrategy:
          column: image_id
          keyGeneratorName: snowflake

    defaultShardingColumn: image_id
    bindingTables:
      - dhs_annotation_gt,dhs_annotation_pred,dhs_origin_annotation_pred
    defaultDatabaseStrategy:
      standard:
        shardingColumn: image_id
        shardingAlgorithmName: database_inline
    defaultTableStrategy:
      none:

    shardingAlgorithms:
      database_inline:
        type: INLINE
        props:
          algorithm-expression: ds_0
      dhs_annotation_gt_inline:
        type: HASH_MOD
        props:
          sharding-count: 2
      dhs_annotation_pred_inline:
        type: HASH_MOD
        props:
          sharding-count: 2
      dhs_origin_annotation_pred_inline:
        type: HASH_MOD
        props:
          sharding-count: 2

    keyGenerators:
      snowflake:
        type: SNOWFLAKE


props:
  sql-show: true

标签:jdbc,shardingsphere,ds0,datasource,spring,sharding,dhs
From: https://www.cnblogs.com/edclol/p/17282450.html

相关文章

  • JDBC概括
    JDBC(JavaDataBaseConnectivity):就是使用java语言操作关系型数据库的一套API本质上就是一套规则,各个数据库提供jar包,执行的是jar中的实现类。基本步骤:0.创建工程,导入驱动jar包  1.注册驱动:class.forName(" ");//要注意jar包的版本且在5.0版本后可以省略该语句。......
  • JDBC驱动类型
    1.JDBC-ODBCBridgeDriverSUN发布JDBC规范时,市场上可用的JDBC驱动程序并不多,但是已经逐渐成熟的ODBC方案使得通过ODBC驱动程序几乎可以连接所有类型的数据源。所以SUN发布了JDBC-ODBC的桥接驱动,利用现成的ODBC架构将JDBC调用转换为ODBC调用,避免了JDBC无驱动可用的窘境,如图2-6所示......
  • JDBC和MyBatis数据库访问技术
    传统的JavaWeb应用开发时,一般使用JDBC进行数据库连接和操作SQL命令。但是,随着互联网技术的飞速发展,使用JDBC已经满足不了项目的开发需求,出现了Hibernate、MyBatis等一些优秀的持久层框架,它们结合了JDBC的优点,使得开发简捷、规范、快速,系统易维护、易扩展。1.1JDBC数据库访......
  • JDBC--宋红康老师讲解版本笔记
    第1章:JDBC概述1.1数据的持久化持久化(persistence):把数据保存到可掉电式存储设备中以供之后使用。大多数情况下,特别是企业级应用,数据持久化意味着将内存中的数据保存到......
  • 一直报错Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.j
    按照网上的提示在pom.xml添加了依赖<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.11</version></depen......
  • Spring中使用JdbcTemplate操作数据库
    JDBC是Java提供的一种用于执行SQL语句的API,可以对多种关系型数据库(例如MySQL、Oracle等)进行访问。但在实际的企业级应用开发中,却很少有人直接使用原生的JDBCAPI......
  • mysql jdbc 通过SSH Tunnel连接MySQL数据库
    1.pom.xml参考JDBC通过SSHTunnel连接MySQL数据库<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifa......
  • sharding-jdbc使用注意事项
    1使用原则 1)单表数据量达到5000万以上,考虑使用分库分表方案分表 2)读写分离可以考虑使用2列设计规范 1)主键使用bigint类型,使用雪花算法生成 2)禁止使用外键 ......
  • poi 导入excel (懒人拷贝代码用)(jdbctemplate)oms版本
     相关内容:1,jdbcTemplate批量导入2,js原始产生form动态产生文件选择框3,反射机制调用set方法 <divclass="l-bar-separator"></div><divclass="group"><aclass="linkad......
  • Java使用IntelliJ IDEA创建控制台程序并通过JDBC连接到数据库
    1、创建一个java控制台程序并测试首先,直接新建一个默认的空的Java模块即可,随便取个名字在src目录下右键->新建->创建一个包,随便取个名字在包中创建一个Test类,写个helloworld......