数据分片分库分表方案

FreeGuideOnline 最新 2026-07-14

yaml spring: shardingsphere: datasource: names: ds0, ds1 ds0: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver jdbc-url: jdbc:mysql://localhost:3306/ds0 username: root password: root ds1: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver jdbc-url: jdbc:mysql://localhost:3306/ds1 username: root password: root sharding: 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: order_id type: SNOWFLAKE default-database-strategy: inline: sharding-column: user_id algorithm-expression: ds$->{user_id % 2}