sub_db/src/main/resources/application.yml
2022-11-05 21:39:29 +08:00

48 lines
1.6 KiB
YAML

spring:
application:
name: springboot-init
# ShardingSphere 配置项
shardingsphere:
datasource:
# 所有数据源的名字
names: db0,db1
# 订单 orders 数据源配置 00
# 订单 orders 数据源配置 01
db0:
type: com.zaxxer.hikari.HikariDataSource # 使用 Hikari 数据库连接池
driver-class-name: com.mysql.jdbc.Driver
jdbc-url: jdbc:mysql://120.26.194.135:3306/db0?useSSL=false&useUnicode=true&characterEncoding=UTF-8
username: db0
password: xyy
db1:
type: com.zaxxer.hikari.HikariDataSource # 使用 Hikari 数据库连接池
driver-class-name: com.mysql.jdbc.Driver
jdbc-url: jdbc:mysql://120.26.194.135:3306/db1?useSSL=false&useUnicode=true&characterEncoding=UTF-8
username: db1
password: xyy
# 分片规则
sharding:
tables:
# orders 表配置
orders:
actualDataNodes: db${0..1}.orders_${0..7} # 映射到 ds-orders-0 和 ds-orders-1 数据源的 orders 表们
databaseStrategy:
inline:
sharding-column: user_id
algorithm-expression: db${user_id % 2}
tableStrategy:
inline:
sharding-column: user_id
algorithm-expression: orders_${user_id % 8}
# 拓展属性配置
props:
sql:
show: true # 打印 SQL
server:
port: 7529
servlet:
context-path: /api
mybatis:
mapper-locations: classpath*:src/main/resources/mapper/*.xml
type-aliases-package: com.yupi.project.model.entity