mysql单库分表配置

 
依赖:
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
<version>4.0.0-RC2</version>
</dependency>

<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-namespace</artifactId>
<version>4.0.0-RC2</version>
</dependency>


mybatis分布式id

mybatis-plus:
configuration:
cache-enabled: false
map-underscore-to-camel-case: true
mapper-locations: classpath:mapper/**/*Mapper.xml
typeAliasesPackage: com.dh.hxcloud.facility.domain.pojo
global-config:
#主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
#若采用雪花算法生成id,需要在生成的实体类中将id的type = IdType.AUTO去掉
id-type: 0
#字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
field-strategy: 2
#驼峰下划线转换
db-column-underline: true
#刷新mapper 调试神器
#refresh-mapper: true
#数据库大写下划线转换
#capital-mode: true
# Sequence序列接口实现类配置
#逻辑删除配置(下面3个配置)
logic-delete-value: Y
logic-not-delete-value: N
#sql-injector: com.nky.pork.quality.standard.conf.MybatisPlusConfig
configuration:
#配置返回数据库(column下划线命名&&返回java实体是驼峰命名),自动匹配无需as(没开启这个,SQL需要写as: select user_id as userId)
map-underscore-to-camel-case: true
cache-enabled: false
#配置JdbcTypeForNull, oracle数据库必须配置
jdbc-type-for-null: 'null'






YML配置:
spring:
  shardingsphere:
    datasource:
      names: access_device
      access_device:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://10.35.227.217:3306/access_device?zeroDateTimeBehavior=convertToNull&amp;useUnicode=true&amp;characterEncoding=utf-8&allowMultiQueries=true&serverTimezone=Asia/Shanghai
        username: mysql
        password: R7VuVj4M
    sharding:
      tables:
        device:表名
          actual-data-nodes: access_device.device_$->{0..7}分表 0表到7表
          table-strategy:
            key-generator:
              column: id
              type: SNOWFLAKE
            inline:
              sharding-column: company_id 按照哪个字段分
              algorithm-expression: device_$->{company_id % 8} 分表策略
        detector:
          table-strategy:
            key-generator:
              column: id
              type: SNOWFLAKE
            inline:
              sharding-column: company_id
              algorithm-expression: detector_$->{company_id % 8}
    props:
      #      是否打印逻辑SQL语句和实际SQL语句,建议调试时打印,在生产环境关闭
      sql:
        show: true
  rabbitmq:
    host: 10.35.227.217
    password: dahuatech
    port: 5672
    publisher-returns: true
    username: test
    virtual-host: /
  redis:
    host: 10.35.227.217
    password: dh-qQ3j!soft
    port: 6380
  data:
    mongodb:
      uri: mongodb://10.35.227.215:30001,10.35.227.216:30001,10.35.227.217:30001/managerDeviceLogs
feign:
  hystrix:
    enabled: true
    command:
      default:
        execution:
          isolation:
            thread:
              timeoutInMilliseconds: 20000
ribbon:
  ConnectTimeout: 5000
  ReadTimeout: 2000
  OkToRetryOnAllOperations: true
  MaxAutoRetries: 1
  MaxAutoRetriesNextServer: 2
 
posted @ 2021-06-02 10:49  liberalartsy  阅读(255)  评论(0)    收藏  举报