Closed w350727743 closed 3 years ago
在学习sharding-jdbc读写分离时候,遇到读写无法分开的问题,希望大佬能帮忙看一下。非常感谢! `
spring.shardingsphere.datasource.names=demo,demo1,demo2
spring.shardingsphere.datasource.common.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.common.driver-class-name=com.mysql.jdbc.Driver spring.shardingsphere.datasource.common.username=root spring.shardingsphere.datasource.common.password= 123456
spring.shardingsphere.datasource.demo.jdbc-url=jdbc:mysql://localhost:3306/demo?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
spring.shardingsphere.datasource.demo1.jdbc-url=jdbc:mysql://localhost:3306/demo1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8 spring.shardingsphere.datasource.demo2.jdbc-url=jdbc:mysql://localhost:3306/demo2?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.write-data-source-name=demo
spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.read-data-source-names=demo1,demo2
spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.load-balancer-name=round_robin
spring.shardingsphere.rules.readwrite-splitting.load-balancers.round_robin.type=ROUND_ROBIN
spring.shardingsphere.props.sql-show=true
mybatis.mapper-locations=classpath:mapper/*.xml mybatis.type-aliases-package=com.lzc.shardingsphererwtest.entity ` springboot版本:2.1.5.RELEASE shardingsphere-jdbc-core-spring-boot-starter版本:5.0.0-alpha demo属于测试中的主库,希望结果在做查询操作时候,读写分离应该读从库demo1,demo2
For English only, other languages will not accept.
在学习sharding-jdbc读写分离时候,遇到读写无法分开的问题,希望大佬能帮忙看一下。非常感谢! `
配置真实数据源
spring.shardingsphere.datasource.names=demo,demo1,demo2
spring.shardingsphere.datasource.common.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.common.driver-class-name=com.mysql.jdbc.Driver spring.shardingsphere.datasource.common.username=root spring.shardingsphere.datasource.common.password= 123456
配置第 1 个数据源
spring.shardingsphere.datasource.demo.jdbc-url=jdbc:mysql://localhost:3306/demo?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
配置第 2 个数据源
spring.shardingsphere.datasource.demo1.jdbc-url=jdbc:mysql://localhost:3306/demo1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8 spring.shardingsphere.datasource.demo2.jdbc-url=jdbc:mysql://localhost:3306/demo2?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
写数据源名称
spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.write-data-source-name=demo
读数据源名称,多个从数据源用逗号分隔
spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.read-data-source-names=demo1,demo2
负载均衡算法名称
spring.shardingsphere.rules.readwrite-splitting.data-sources.pr_ds.load-balancer-name=round_robin
负载均衡算法配置
spring.shardingsphere.rules.readwrite-splitting.load-balancers.round_robin.type=ROUND_ROBIN
打印sql
spring.shardingsphere.props.sql-show=true
mybatis.mapper-locations=classpath:mapper/*.xml mybatis.type-aliases-package=com.lzc.shardingsphererwtest.entity ` springboot版本:2.1.5.RELEASE shardingsphere-jdbc-core-spring-boot-starter版本:5.0.0-alpha demo属于测试中的主库,希望结果在做查询操作时候,读写分离应该读从库demo1,demo2