application.yml 6.6 KB
Newer Older
1 2 3 4 5 6 7 8 9
spring:
  profiles:
    active: sharding
mybatis:
  config-location: classpath:META-INF/mybatis-config.xml

---
spring:
  profiles: sharding
武汉红喜's avatar
武汉红喜 已提交
10
  shardingsphere:
11
    datasource:
12 13
      names: ds0,ds1
      ds0:
14
        type: org.apache.commons.dbcp.BasicDataSource
15
        driver-class-name: com.mysql.cj.jdbc.Driver
武汉红喜's avatar
武汉红喜 已提交
16
        url: jdbc:mysql://db.hongxi.org:3306/demo_ds_0
17
        username: root
武汉红喜's avatar
武汉红喜 已提交
18
        password: n36bxXMnHina
19
      ds1:
20
        type: org.apache.commons.dbcp.BasicDataSource
21
        driver-class-name: com.mysql.cj.jdbc.Driver
武汉红喜's avatar
武汉红喜 已提交
22
        url: jdbc:mysql://db.hongxi.org:3306/demo_ds_1
23
        username: root
武汉红喜's avatar
武汉红喜 已提交
24
        password: n36bxXMnHina
武汉红喜's avatar
武汉红喜 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
    sharding:
      default-database-strategy:
        inline:
          sharding-column: user_id
          algorithm-expression: ds${user_id % 2}
      tables:
        t_order:
          actual-data-nodes: ds${0..1}.t_order_${0..1}
          table-strategy:
            inline:
              sharding-column: order_id
              algorithm-expression: t_order_${order_id % 2}
          key-generator-column-name: order_id
        t_order_item:
          actual-data-nodes: ds${0..1}.t_order_item_${0..1}
          table-strategy:
            inline:
              sharding-column: order_id
              algorithm-expression: t_order_item_${order_id % 2}
          key-generator-column-name: order_item_id
45 46 47 48

---
spring:
  profiles: sharding-db
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
  shardingsphere:
    sharding:
      default-database-strategy:
        inline:
          algorithm-expression: ds_${user_id % 2}
          sharding-column: user_id
      tables:
        t_order:
          actual-data-nodes: ds_${0..1}.t_order
          key-generator-column-name: order_id
        t_order_item:
          actual-data-nodes: ds_${0..1}.t_order_item
          key-generator-column-name: order_item_id
    datasource:
      ds_0:
        driver-class-name: com.mysql.cj.jdbc.Driver
        password: ''
        type: org.apache.commons.dbcp.BasicDataSource
        url: jdbc:mysql://localhost:3306/demo_ds_0
        username: root
      ds_1:
        driver-class-name: com.mysql.cj.jdbc.Driver
        password: ''
        type: org.apache.commons.dbcp.BasicDataSource
        url: jdbc:mysql://localhost:3306/demo_ds_1
        username: root
      names: ds_0,ds_1
76 77 78 79

---
spring:
  profiles: sharding-tbl
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
  shardingsphere:
    sharding:
      tables:
        t_order:
          actual-data-nodes: ds.t_order_${0..1}
          key-generator-column-name: order_id
          table-strategy:
            inline:
              algorithm-expression: t_order_${order_id % 2}
              sharding-column: order_id
        t_order_item:
          actual-data-nodes: ds.t_order_item_${0..1}
          key-generator-column-name: order_item_id
          table-strategy:
            inline:
              algorithm-expression: t_order_item_${order_id % 2}
              sharding-column: order_id
    datasource:
      ds:
        driver-class-name: com.mysql.cj.jdbc.Driver
        password: ''
        type: org.apache.commons.dbcp.BasicDataSource
        url: jdbc:mysql://localhost:3306/demo_ds
        username: root
      names: ds
105 106 107 108

---
spring:
  profiles: masterslave
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
  shardingsphere:
    masterslave:
      load-balance-algorithm-type: round_robin
      master-data-source-name: ds_master
      name: ds_ms
      slave-data-source-names: ds_slave_0,ds_slave_1
    datasource:
      ds_master:
        driver-class-name: com.mysql.cj.jdbc.Driver
        password: ''
        type: org.apache.commons.dbcp.BasicDataSource
        url: jdbc:mysql://localhost:3306/demo_ds_master
        username: root
      ds_slave_0:
        driver-class-name: com.mysql.cj.jdbc.Driver
        password: ''
        type: org.apache.commons.dbcp.BasicDataSource
        url: jdbc:mysql://localhost:3306/demo_ds_slave_0
        username: root
      ds_slave_1:
        driver-class-name: com.mysql.cj.jdbc.Driver
        password: ''
        type: org.apache.commons.dbcp.BasicDataSource
        url: jdbc:mysql://localhost:3306/demo_ds_slave_1
        username: root
      names: ds_master,ds_slave_0,ds_slave_1
135 136 137 138

---
spring:
  profiles: sharding-masterslave
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
  shardingsphere:
    sharding:
      default-database-strategy:
        inline:
          algorithm-expression: ds_${user_id % 2}
          sharding-column: user_id
      master-slave-rules:
        ds_0:
          master-data-source-name: ds_master_0
          slave-data-source-names: ds_master_0_slave_0, ds_master_0_slave_1
        ds_1:
          master-data-source-name: ds_master_1
          slave-data-source-names: ds_master_1_slave_0, ds_master_1_slave_1
      tables:
        t_order:
          actual-data-nodes: ds_${0..1}.t_order_${0..1}
          key-generator-column-name: order_id
          table-strategy:
            inline:
              algorithm-expression: t_order_${order_id % 2}
              sharding-column: order_id
        t_order_item:
          actual-data-nodes: ds_${0..1}.t_order_item_${0..1}
          key-generator-column-name: order_item_id
          table-strategy:
            inline:
              algorithm-expression: t_order_item_${order_id % 2}
              sharding-column: order_id
    datasource:
      ds_master_0:
        driver-class-name: com.mysql.cj.jdbc.Driver
        password: ''
        type: org.apache.commons.dbcp.BasicDataSource
        url: jdbc:mysql://localhost:3306/demo_ds_master_0
        username: root
      ds_master_0_slave_0:
        driver-class-name: com.mysql.cj.jdbc.Driver
        password: ''
        type: org.apache.commons.dbcp.BasicDataSource
        url: jdbc:mysql://localhost:3306/demo_ds_master_0_slave_0
        username: root
      ds_master_0_slave_1:
        driver-class-name: com.mysql.cj.jdbc.Driver
        password: ''
        type: org.apache.commons.dbcp.BasicDataSource
        url: jdbc:mysql://localhost:3306/demo_ds_master_0_slave_1
        username: root
      ds_master_1:
        driver-class-name: com.mysql.cj.jdbc.Driver
        password: ''
        type: org.apache.commons.dbcp.BasicDataSource
        url: jdbc:mysql://localhost:3306/demo_ds_master_1
        username: root
      ds_master_1_slave_0:
        driver-class-name: com.mysql.cj.jdbc.Driver
        password: ''
        type: org.apache.commons.dbcp.BasicDataSource
        url: jdbc:mysql://localhost:3306/demo_ds_master_1_slave_0
        username: root
      ds_master_1_slave_1:
        driver-class-name: com.mysql.cj.jdbc.Driver
        password: ''
        type: org.apache.commons.dbcp.BasicDataSource
        url: jdbc:mysql://localhost:3306/demo_ds_master_1_slave_1
        username: root
      names: ds_master_0,ds_master_1,ds_master_0_slave_0,ds_master_0_slave_1,ds_master_1_slave_0,ds_master_1_slave_1