当前位置:网站首页>使用shardingjdbc实现读写分离配置
使用shardingjdbc实现读写分离配置
2022-08-08 12:23:00 【woshihedayu】
1、相关的依赖如下
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
<version>5.1.2</version>
</dependency>
2、相关配置如下
spring:
shardingsphere:
datasource:
names: m0,s0
m0:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.182.128:3306/user_db?serverTimezone=Asia/Shanghai
username: root
password: 123456
s0:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.182.128:3307/user_db?serverTimezone=Asia/Shanghai
username: root
password: 123456
rules:
readwrite-splitting:
data-sources:
readwrite_ds: #定义读写分离数据源
type: Static
props:
write-data-source-name: m0
read-data-source-names: s0
sharding:
tables:
t_user:
actual-data-nodes: readwrite_ds.t_user #声明读写分离数据源中的表
props:
sql-show: true
main:
allow-bean-definition-overriding: true
基于MySQL主从复制实现,其中m0是mysql的主库数据源,s0是mysql的从库数据源,具体配置一定要根据shardingjdbc的版本来写,不同的版本差异很大,查看官方文档一旦选错了版本,运行出现问题,很难发现错在哪里,浪费了很多时间!
边栏推荐
- 【C语言】动态内存管理
- (5)FlinkSQL将socket数据写入到mysql方式二
- 处理器的调试接口
- STM32的内存管理相关(内存架构,内存管理,map文件分析)
- Jenkins - install (2)
- Some optional strategies and usage scenarios for PWA application Service Worker caching
- 宏任务和微任务——三目算符与加号优先级——原生的js如何禁用button——0xff ^ 33 的结果是——in的用法——正则匹配网址
- 海外邮件发送指南(一)
- C语言小项目 -- 通讯录(静态版+动态版+文件版)
- 案例分析 | 宜家以双钻设计模型探索线上零售新业务
猜你喜欢
随机推荐
RT-Thread记录(三、RT-Thread 线程操作函数及线程管理与FreeRTOS的比较)
[C language] file related operations
MeterSphere - open source test platform
MySQL----索引
爱可可AI前沿推介(8.8)
面试官问你什么是长轮询?
Jenkins-安装(2)
在半小时内从无到有开发并调试一款Chrome扩展(Chrome插件/谷歌浏览器插件)
curl获取harbor镜像仓库项目下的镜像列表
MySQL Dual-Master 双向同步
一文读懂配置管理(CM)
Mobile adaptation method of vw/vh - vw/vh instance - analog B stand mobile home page - get style tutorial video
Pattern Recognition Study Notes: Chapter 6 Other Classification Methods (Continuously updated...)
什么是IP SSL证书,如何申请?
【C语言】自定义类型详解:结构体、枚举、联合
In-depth analysis of the soul of C language -- pointer
探究!一个数据包在网络中的心路历程
安装MinGW-w64
开放原子开源峰会 - SmartIDE正式开源并发布v1.0版本
手绘地图制作的关键点之“图层覆盖”








