From 5d0ac13ae68cbe279e3b9ed412ba49c3f3708972 Mon Sep 17 00:00:00 2001
From: xiongxiaoyang <773861846@qq.com>
Date: Fri, 3 Jun 2022 20:57:23 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E9=9B=86=E6=88=90=20ShardingSphere-JDB?=
=?UTF-8?q?C=20=E6=9C=80=E6=96=B0=E7=89=88=EF=BC=8C=E5=88=86=E8=A1=A8?=
=?UTF-8?q?=E5=AD=98=E5=82=A8=E5=B0=8F=E8=AF=B4=E5=86=85=E5=AE=B9=EF=BC=88?=
=?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=85=B3=E9=97=AD=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
默认关闭分库分表,通过配置属性 shardingsphere.enabled 来开启
---
pom.xml | 8 +++++++
src/main/resources/application.yml | 38 ++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/pom.xml b/pom.xml
index ea01fdf..552c38f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,6 +21,7 @@
8.2.0
2.3.1
1.8.4
+ 5.1.1
@@ -137,6 +138,13 @@
${sentinel.version}
+
+
+ org.apache.shardingsphere
+ shardingsphere-jdbc-core-spring-boot-starter
+ ${shardingsphere-jdbc.version}
+
+
mysql
mysql-connector-java
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 5db5605..7a06a9e 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -20,6 +20,44 @@ spring:
url: jdbc:mysql://localhost:3306/novel_test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: test123456
+ # 分库分表配置
+ shardingsphere:
+ datasource:
+ names: ds_0
+ ds_0:
+ type: com.zaxxer.hikari.HikariDataSource
+ driverClassName: com.mysql.cj.jdbc.Driver
+ jdbcUrl: jdbc:mysql://localhost:3306/novel_test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
+ username: root
+ password: test123456
+ rules:
+ sharding:
+ tables:
+ # book_content表
+ book_content:
+ # 数据节点
+ actual-data-nodes: ds_$->{0}.book_content$->{0..9}
+ # 分表策略
+ table-strategy:
+ standard:
+ # 分片列名称
+ sharding-column: chapter_id
+ # 分片算法名称
+ sharding-algorithm-name: bookContentSharding
+ sharding-algorithms:
+ bookContentSharding:
+ # 行表达式分片算法,使用 Groovy 的表达式,提供对 SQL 语句中的 = 和 IN 的分片操作支持
+ type: INLINE
+ props:
+ # 分片算法的行表达式
+ algorithm-expression: book_content$->{chapter_id % 10}
+ props:
+ # 是否在日志中打印 SQL
+ sql-show: true
+ # 是否开启分库分表
+ enabled: false
+
+
config:
activate:
on-profile: dev