当前位置:Gxlcms > 数据库问题 > ShardingSphere系列(一)——ShardingSphere-JDBC初体验

ShardingSphere系列(一)——ShardingSphere-JDBC初体验

时间:2021-07-01 10:21:17 帮助过:70人阅读

=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.ds0.driver-class-name=com.mysql.cj.jdbc.Driver spring.shardingsphere.datasource.ds0.jdbc-url=jdbc:mysql://192.168.31.127:13306/ds0 spring.shardingsphere.datasource.ds0.username=root spring.shardingsphere.datasource.ds0.password=123456 spring.shardingsphere.datasource.ds1.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.ds1.driver-class-name=com.mysql.cj.jdbc.Driver spring.shardingsphere.datasource.ds1.jdbc-url=jdbc:mysql://192.168.31.127:13306/ds1 spring.shardingsphere.datasource.ds1.username=root spring.shardingsphere.datasource.ds1.password=123456

2.分库规则

spring.shardingsphere.rules.sharding.tables.t_order.actual-data-nodes=ds$->{0..1}.t_order

3.声明分片键和分片算法

spring.shardingsphere.rules.sharding.tables.t_order.database-strategy.standard.sharding-column=order_id
spring.shardingsphere.rules.sharding.tables.t_order.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=ds$->{order_id % 2}

4.配置snowflake作为主键生成算法

spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.column=order_id
spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.key-generator-name=snowflake

spring.shardingsphere.rules.sharding.key-generators.snowflake.type=SNOWFLAKE
spring.shardingsphere.rules.sharding.key-generators.snowflake.props.worker-id=1
spring.shardingsphere.rules.sharding.key-generators.snowflake.props.max-vibration-offset=1
spring.shardingsphere.rules.sharding.key-generators.snowflake.props.max-tolerate-time-difference-milliseconds=10

 

ShardingSphere系列(一)——ShardingSphere-JDBC初体验

标签:-o   轻量   lin   sql   orm   sid   版本   介绍   prope   

人气教程排行