spring-boot-sharding-sphere
spring-boot-sharding-sphere copied to clipboard
4-分库分表-读写分离问题
为什么我的 分表最后结果是这样的,每个表都会插入一份呢,烦请告知
为什么我的 分表最后结果是这样的,每个表都会插入一份呢,烦请告知
你有没有按照id进行分表插入
spring:
application:
name: shardingsphere
shardingsphere:
datasource:
names: master0,slave0,master1,slave1
master0:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.2.106:3306/fox_db_0?useSSL=false&serverTimezone=UTC
username: root
password: 123456
slave0:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.2.107:3306/fox_db_0?useSSL=false&serverTimezone=UTC
username: root
password: 123456
master1:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.2.106:3306/fox_db_1?useSSL=false&serverTimezone=UTC
username: root
password: 123456
slave1:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.2.107:3306/fox_db_1?useSSL=false&serverTimezone=UTC
username: root
password: 123456
sharding:
default-database-strategy:
inline:
sharding-column: id
algorithm-expression: master$->{age % 2}
tables:
fox_user:
actual-data-nodes: master$->{0..1}.fox_user_$->{0..3}
table-strategy:
inline:
sharding-column: id
algorithm-expression: fox_user_$->{id % 2}
#读写分离
master-slave-rules:
master0:
master-data-source-name: master0
slave-data-source-names: slave0
master1:
master-data-source-name: master1
slave-data-source-names: slave1
masterslave:
#从库负载均衡算法类型,可选值:ROUND_ROBIN,RANDOM。
#若load-balance-algorithm-class-name
存在则忽略该配置
load-balance-algorithm-type: round_robin
name: ms
#打印sql语句
props:
sql:
show: true
check:
table:
metadata:
# 是否在启动时检查分表元数据一致性
enabled: true
因为Druid数据源和默认的数据源冲突,添加此配置 出现重复进行覆盖
main: allow-bean-definition-overriding: true
老铁帮忙看一下怎么这个是错误的啊?启动都报错: 949406202谢谢联系一下