springboot - sharding-jdbc配置以及注意点

springboot 配置文件

spring.shardingsphere.datasource.names=db0,db1

# 数据源 db0 配置
spring.shardingsphere.datasource.db0.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.db0.driver-class-name=com.mysql.cj.jdbc.Driver
# 注意  这里不是以前的url
spring.shardingsphere.datasource.db0.jdbc-url=jdbc:mysql://192.168.139.101:3306/test?characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2b8
spring.shardingsphere.datasource.db0.username=da
spring.shardingsphere.datasource.db0.password=dashan007@

# 数据源 db1 配置
spring.shardingsphere.datasource.db1.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.db1.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.db1.jdbc-url=jdbc:mysql://192.168.139.103:3306/test?characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2b8
spring.shardingsphere.datasource.db1.username=da
spring.shardingsphere.datasource.db1.password=dashan007@

# 真实数据节点表达式
spring.shardingsphere.sharding.tables.t_order.actual-data-nodes=db$->{0..1}.t_order_$->{0..1}

# 分库策略
spring.shardingsphere.sharding.tables.t_order.database-strategy.inline.sharding-column=spu_id
spring.shardingsphere.sharding.tables.t_order.database-strategy.inline.algorithm-expression=db$->{spu_id % 2}
# 分表策略
spring.shardingsphere.sharding.tables.t_order.table-strategy.inline.sharding-column=id
spring.shardingsphere.sharding.tables.t_order.table-strategy.inline.algorithm-expression=t_order_$->{id % 2}

# 广播表 / 全局表
spring.shardingsphere.sharding.broadcast-tables=area

mybatis.mapper-locations=classpath:/mappers/*.xml
logging.pattern.dateformat=HH:mm:ss
spring:
  shardingsphere:
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值