apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.87k stars 6.73k forks source link

读写无法分开 #10256

Closed w350727743 closed 3 years ago

w350727743 commented 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

配置第 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 image demo属于测试中的主库,希望结果在做查询操作时候,读写分离应该读从库demo1,demo2

terrymanu commented 3 years ago

For English only, other languages will not accept.