# 表明使用单机模式 #https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/mode/ mode: type: Standalone repository: type: JDBC # 配置数据源 # https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/data-source/ dataSources: # 配置主数据库(master3306可以写自己的名字) master3306: driverClassName: com.mysql.cj.jdbc.Driver dataSourceClassName: com.zaxxer.hikari.HikariDataSource jdbcUrl: jdbc:mysql://192.168.0.209/tnb_content_tdb?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8 username: test password: Test@123456 # 配置从数据库(salve3308可以写自己的名字) slave3307: driverClassName: com.mysql.cj.jdbc.Driver dataSourceClassName: com.zaxxer.hikari.HikariDataSource jdbcUrl: jdbc:mysql://192.168.0.209/tnb_content_tdb?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8 username: test password: Test@123456 # 配置规则 rules: # 单表规则用于指定哪些单表需要被 ShardingSphere 管理,也可设置默认的单表数据源。 - !SINGLE tables: - "*.*" # 加载全部单表 # defaultDataSource: master3306 # 默认数据源,仅在执行 CREATE TABLE 创建单表时有效。缺失值为空,表示随机单播路由。 # 声明使用读写分离规则 # https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/readwrite-splitting/ - !READWRITE_SPLITTING dataSourceGroups: readwrite_ds: #读写分离逻辑数据源名称 writeDataSourceName: master3306 #写库数据源名称 readDataSourceNames: #读库数据源名称 - slave3307 transactionalReadQueryStrategy: PRIMARY # 事务内读请求的路由策略,可选值:PRIMARY(路由至主库)、FIXED(同一事务内路由至固定数据源)、DYNAMIC(同一事务内路由至非固定数据源)。默认值:DYNAMIC loadBalancerName: round-robin # 负载均衡算法名称 # 负载均衡算法配置 loadBalancers: round-robin: # 负载均衡算法名称 type: ROUND_ROBIN # 负载均衡算法类型 # 属性配置 props: # 是否显示执行的SQL语句 sql-show: false