上篇博客,我们讲了 ShardingSphere实战(4)- 广播表和默认数据源 ,这篇博客,我们实现一下读写分离。
一、读写分离配置
# sharding-jdbc 读写分离策略
# 给数据源起别名,这里名称需要和下面的一致
spring.shardingsphere.datasource.names=master,slave0,slave1
# 配置数据源
spring.shardingsphere.datasource.master.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.master.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.master.jdbc-url=jdbc:mysql://xxx:3316/master?serverTimezone=UTC&useSSL=false
spring.shardingsphere.datasource.master.username=xxx
spring.shardingsphere.datasource.master.password=xxx
spring.shardingsphere.datasource.slave0.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.slave0.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.slave0.jdbc-url=jdbc:mysql://xxx:3316/slave0?serverTimezone=UTC&useSSL=false
spring.shardingsphere.datasource.slave0.username=xxx
spring.shardingsphere.datasource.slave0.password=xxx
spring.shardingsphere.datasource.slave1.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.slave1.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.slave1.jdbc-url=jdbc:mysql://xxx/slave1?serverTimezone=UTC&useSSL=false<
ShardingSphere读写分离实践

最低0.47元/天 解锁文章
2810

被折叠的 条评论
为什么被折叠?



