当前位置:网站首页>使用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的版本来写,不同的版本差异很大,查看官方文档一旦选错了版本,运行出现问题,很难发现错在哪里,浪费了很多时间!
边栏推荐
- Replication监控及自动故障切换
- 作为一个年薪50W阿里P7架构师的必备知识:并发+JVM+多线程+Netty+MySQL
- 是不是只有字符串的数字水印能一直保留并且不影响计算,其他类型的字段导入数据库之后水印就会丢失?
- win10安装Solidworks2016安装出错:solidworks\sldfuncfeat.dll“ 已返回 0x3,如何解决.
- Mobile adaptation method of vw/vh - vw/vh instance - analog B stand mobile home page - get style tutorial video
- 论文阅读《Omnidirectional DSO: Direct Sparse Odometry with Fisheye Cameras》
- 探究!一个数据包在网络中的心路历程
- 安科瑞预付费水电集团物业解决方案-Susie 周
- 处理器的调试接口
- (原创)[C#] GDI+ 之鼠标交互:原理、示例、一步步深入、性能优化
猜你喜欢
Doris学习笔记之优化
IJCAI 2022 | 基于随机游走聚合的图神经网络
[Horizon Rising Sun X3 Trial Experience] WIFI connection, SSH login, TogetherROS installation (section 2)
shell之常用小工具
Redis的那些事:一文入门Redis的基础操作
转转商品系统高并发实战(数据篇)
别再到处乱放配置文件了!试试我司使用 7 年的这套解决方案,稳的一秕
The programmer essential VS debugging technique
如何在go重打印函数调用者信息Caller
【C语言】自定义类型详解:结构体、枚举、联合
随机推荐
爱可可AI前沿推介(8.8)
详解轮播图二-通过left定位来轮播图片
Some optional strategies and usage scenarios for PWA application Service Worker caching
【C语言】动态内存管理
一些常见的web小功能
老手也常误用!详解 Go channel 内存泄漏问题
node中package解析、npm 命令行npm详解,node中的common模块化,npm、nrm两种方式查看源和切换镜像
Jenkins-安装(2)
迁移学习(Transfer Learning)的背景、历史及学习课
论文阅读《Omnidirectional DSO: Direct Sparse Odometry with Fisheye Cameras》
安科瑞预付费水电集团物业解决方案-Susie 周
大缓存更强劲,搭载AMD Milan-X的浪潮GPU服务器NF5468A5深度评测
TF-GNN踩坑记录(一)
The most complete JVM performance tuning in history: thread + subsystem + class loading + memory allocation + garbage collection
[C language] Detailed explanation of custom types: structure, enumeration, union
(5)FlinkSQL将socket数据写入到mysql方式二
Jenkins - Introduction to Continuous Integration (1)
五面阿里巴巴拿offer后定级P6:分享自己的面试经历
(6)FlinkSQL将kafka数据写入到mysql方式一
Combining "xPlus" to discuss the innovation and change of software architecture