shardingsphere-jdbc有四个分片规则
使用在springboot环境下使用
配置org.apache.shardingsphere sharding-jdbc-spring-boot-starter4.1.1 <还有Mybatis依赖> org.apache.shardingsphere sharding-transaction-xa-core4.1.1
spring:
main:
allow-bean-definition-overriding: true
shardingsphere:
datasource:
names: m1,m2 # 代表两个库
m1:
type: com.alibaba.druid.pool.DruidDataSource
driver-calss-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mysql?characterEncoding=utf-8&useSSL=false&serverTimezone=Hongkong&allowPublicKeyRetrieval=true
username: root
password: MyNewPass4!
m2:
type: com.alibaba.druid.pool.DruidDataSource
driver-calss-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&useSSL=false&serverTimezone=Hongkong&allowPublicKeyRetrieval=true
username: root
password: MyNewPass4!
sharding:
tables:
person:
actual-data-nodes: m$->{1..2}.person
key-generator:
column: id
type: SNOWFLAKE
props:
worker:
id: 1
# table-strategy:
# inline:
# sharding-column: id
# algorithm-expression: person->{id%2+1}
database-strategy:
# inline:
# sharding-column: id
# algorithm-expression: m$->{id%2+1}
# standard:
# sharding-column: id
# precise-algorithm-class-name: org.miao.algorithm.DataBaseStandardPrecise
# range-algorithm-class-name: org.miao.algorithm.DataBaseStandardRange
# complex:
# sharding-column: id,name
# algorithm-class-name: org.miao.algorithm.DataBaseComplex
hint:
algorithm-class-name: org.miao.algorithm.DataBaseHintStrategy
props:
sql:
show: true
inline
standard
通过自定义分片策略实现精确分片和范围分片
complex通过多分片键实现精确分片
hint强制分片,通过非SQL方式强制干预



