其他分享
首页 > 其他分享> > shardingjdbc配置文件配置

shardingjdbc配置文件配置

作者:互联网

spring.main.allow-bean-definition-overriding = true
#sharding-jdbc分片规则配置
#数据源  m1可以自己定义
spring.shardingsphere.datasource.names = m1

# 这里的m1就是上面的数据源名称
spring.shardingsphere.datasource.m1.type = com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.m1.driver-class-name = com.mysql.jdbc.Driver
spring.shardingsphere.datasource.m1.url = jdbc:mysql://localhost:3306/test?useUnicode=true
spring.shardingsphere.datasource.m1.username = root
spring.shardingsphere.datasource.m1.password = 85586537

# 指定t_order表的数据分布情况,数据库的表为t_order_1和t_order_2,配置数据节点 m1.t_order_1,m1.t_order_2
spring.shardingsphere.sharding.tables.t_order.actual-data-nodes = m1.t_order_$->{1..2}

# 指定t_order表的主键order_id的生成策略为SNOWFLAKE
spring.shardingsphere.sharding.tables.t_order.key-generator.column=order_id
spring.shardingsphere.sharding.tables.t_order.key-generator.type=SNOWFLAKE

# 指定t_order表的分片策略,分片策略包括分片键和分片算法
spring.shardingsphere.sharding.tables.t_order.table-strategy.inline.sharding-column = order_id
spring.shardingsphere.sharding.tables.t_order.table-strategy.inline.algorithm-expression = t_order_$->{order_id % 2 + 1}

# 打开sql输出日志
spring.shardingsphere.props.sql.show = true

  

mysql数据库不用配置

标签:配置文件,shardingsphere,配置,m1,datasource,spring,sharding,shardingjdbc,order
来源: https://www.cnblogs.com/zengjiao/p/14644070.html