Spring Boot starter 数据分片配置说明
# 数据源的公共配置spring.shardingsphere.datasource.common.type=com.zaxxer.hikari.HikariDataSourcespring.shardingsphere.datasource.common.driver-class-name=com.mysql.cj.jdbc.Driver# 数据源的名称,下面jdbc-url,username,password得加上数据源名称spring.shardingsphere.datasource.names=test0,test1spring.shardingsphere.datasource.test0.jdbc-url=jdbc:mysql://localhost:3306/test0spring.shardingsphere.datasource.test0.username=rootspring.shardingsphere.datasource.test0.password=Fuyu.742423672spring.shardingsphere.datasource.test1.jdbc-url=jdbc:mysql://localhost:3306/test1spring.shardingsphere.datasource.test1.username=rootspring.shardingsphere.datasource.test1.password=Fuyu.742423672# SQL 日志spring.shardingsphere.props.sql-show=true# 配置test库中的user表规则,表示有两个库,每个库三个表spring.shardingsphere.rules.sharding.tables.user.actual-data-nodes=test$->{0..1}.user_$->{0..2}# 配置user表的分库策略spring.shardingsphere.rules.sharding.tables.user.database-strategy.standard.sharding-column=id# 分库策略的算法名,该值会用在具体算法的配置名中spring.shardingsphere.rules.sharding.tables.user.database-strategy.standard.sharding-algorithm-name=database-inline# 配置分库策略的算法类型,此处为行表达式分片算法spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.type=INLINE# 行表达式分片算法的行表达式spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.props.algorithm-expression=test$->{id % 2}# 配置user表的分表策略spring.shardingsphere.rules.sharding.tables.user.table-strategy.standard.sharding-column=user_idspring.shardingsphere.rules.sharding.tables.user.table-strategy.standard.sharding-algorithm-name=hash-mod# 此处为哈希取模spring.shardingsphere.rules.sharding.sharding-algorithms.hash-mod.type=HASH_MOD# 对3取模spring.shardingsphere.rules.sharding.sharding-algorithms.hash-mod.props.sharding-count=3# 配置user表的主键生成算法,此处采用雪花算法spring.shardingsphere.rules.sharding.tables.user.key-generate-strategy.column=idspring.shardingsphere.rules.sharding.tables.user.key-generate-strategy.key-generator-name=snowflake# 分布式序列算法配置spring.shardingsphere.rules.sharding.key-generators.snowflake.type=SNOWFLAKEspring.shardingsphere.rules.sharding.key-generators.snowflake.props.worker-id=123
