注意点
配置druid连接池的时候,不要用下面这中配置,因为程序启动的时候,会去找spring.datasource中的配置,由于我是删除了该配置,所以启动会报错,解决方法:
换成
单库分表配置。
spring:
#指定数据源
shardingsphere:
datasource:
names: ds0 #可多库配置
#数据源的具体配置
ds0:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/db?serverTimezone=UTC
username: root
password: 123456
#具体的分片规则
rules:
sharding:
tables:
table_name: #用来写sql的虚拟表名
actual-data-nodes: ds0.table_name$->{0..99} #物理表名
table-strategy:
standard:
sharding-column: id
sharding-algorithm-name: table-inline
table_name_name: #用来写sql的虚拟表名
actual-data-nodes: ds0.table_name_name$->{0..1} #物理表名
table-strategy:
standard:
sharding-column: id
sharding-algorithm-name: table-inline #配置
#分片算法
sharding-algorithms:
table-inline:
type: HASH_MOD
props:
sharding-count: 2
#显示执行的sql语句
props:
sql-show: true
sql-comment-parse-enabled: true
mode:
type: Memory
main:
allow-bean-definition-overriding: true