shardingsphere-jdbc的yaml的配置规则
时间: 2024-04-29 20:23:40 浏览: 95
ShardingSphere-JDBC 的 YAML 配置规则如下:
1. 数据源配置
```yaml
dataSources:
ds0:
url: jdbc:mysql://localhost:3306/db0?serverTimezone=UTC
username: root
password: root
driverClassName: com.mysql.jdbc.Driver
ds1:
url: jdbc:mysql://localhost:3306/db1?serverTimezone=UTC
username: root
password: root
driverClassName: com.mysql.jdbc.Driver
```
2. 分片规则配置
```yaml
shardingRule:
tables:
user:
actualDataNodes: ds$->{0..1}.user$->{0..1}
tableStrategy:
standard:
shardingColumn: user_id
preciseAlgorithmClassName: com.xxx.PreciseShardingAlgorithm
rangeAlgorithmClassName: com.xxx.RangeShardingAlgorithm
shardingAlgorithmClassName: com.xxx.ComplexKeysShardingAlgorithm
keyGenerateStrategy:
column: user_id
type: SNOWFLAKE
```
3. 数据库和表的默认分片策略
```yaml
defaultDatabaseStrategy:
standard:
shardingColumn: user_id
preciseAlgorithmClassName: com.xxx.PreciseShardingAlgorithm
rangeAlgorithmClassName: com.xxx.RangeShardingAlgorithm
shardingAlgorithmClassName: com.xxx.ComplexKeysShardingAlgorithm
defaultTableStrategy:
none:
```
4. 数据源和表的映射关系配置
```yaml
props:
sql:
show: true
# 从库负载均衡策略
executor.size: 20
executor.keepAliveSeconds: 300
executor.blockQueueSize: 1000
executor.threadFactory: net.sourceforge.jtds.jdbc.ThreadFactoryImpl
slave.load.balance.strategy.type: ROUND_ROBIN
slave.load.balance.algorithm.type: HASH
# 执行超时时间
max.timeout.milliseconds: 2000
# 是否打印 SQL
sql.show: true
# 是否打印 SQL 时输出原始 SQL
sql.simple: false
# 是否开启动态表路由
dynamic.table: true
# 是否允许表规则不存在,如果不存在则直接路由到主库
allow.table.without.rule: true
# 是否允许无法路由的 SQL 走主库
allow.broadcast.without.sharding: true
```
以上就是 ShardingSphere-JDBC 的 YAML 配置规则。
阅读全文