sharding-jdbc读写分离yml
时间: 2023-10-12 21:06:25 浏览: 112
以下是一个示例的Sharding-JDBC的读写分离配置文件(YAML格式):
```yaml
spring:
shardingsphere:
datasource:
names: ds_master, ds_slave1, ds_slave2
ds_master:
url: jdbc:mysql://localhost:3306/master_db?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: root
type: com.zaxxer.hikari.HikariDataSource
ds_slave1:
url: jdbc:mysql://localhost:3306/slave1_db?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: root
type: com.zaxxer.hikari.HikariDataSource
ds_slave2:
url: jdbc:mysql://localhost:3306/slave2_db?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: root
type: com.zaxxer.hikari.HikariDataSource
masterslave:
name: ms_ds
master-data-source-name: ds_master
slave-data-source-names: ds_slave1, ds_slave2
props:
sql.show: true
```
这里配置了3个数据源,分别为主库和两个从库。`ds_master` 是主库,`ds_slave1` 和 `ds_slave2` 是从库。`masterslave` 配置项指定了主从关系,将主库指定为 `ds_master` ,从库指定为 `ds_slave1` 和 `ds_slave2` 。
阅读全文