Sharding

    1. Configure data sharding rules in the SpringBoot file, including data sources, sharding rules, and global attributes.
    2. Start the SpringBoot program. The configuration is automatically loaded and the ShardingSphereDataSource is initialized.
    1. spring.shardingsphere.mode.type=Standalone
    2. spring.shardingsphere.mode.repository.type=JDBC
    3. spring.shardingsphere.datasource.names=ds-0,ds-1
    4. spring.shardingsphere.datasource.ds-0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
    5. spring.shardingsphere.datasource.ds-0.type=com.zaxxer.hikari.HikariDataSource
    6. spring.shardingsphere.datasource.ds-0.driver-class-name=com.mysql.jdbc.Driver
    7. spring.shardingsphere.datasource.ds-0.username=root
    8. spring.shardingsphere.datasource.ds-0.password=
    9. spring.shardingsphere.datasource.ds-1.type=com.zaxxer.hikari.HikariDataSource
    10. spring.shardingsphere.datasource.ds-1.username=root
    11. spring.shardingsphere.datasource.ds-1.password=
    12. spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-column=user_id
    13. spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-algorithm-name=database-inline
    14. spring.shardingsphere.rules.sharding.binding-tables[0]=t_order,t_order_item
    15. spring.shardingsphere.rules.sharding.broadcast-tables=t_address
    16. spring.shardingsphere.rules.sharding.tables.t_order.actual-data-nodes=ds-$->{0..1}.t_order_$->{0..1}
    17. spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-column=order_id
    18. spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-algorithm-name=t-order-inline
    19. spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.column=order_id
    20. spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.key-generator-name=snowflake
    21. spring.shardingsphere.rules.sharding.tables.t_order.audit-strategy.auditor-names=shardingKeyAudit
    22. spring.shardingsphere.rules.sharding.tables.t_order.audit-strategy.allow-hint-disable=true
    23. spring.shardingsphere.rules.sharding.tables.t_order_item.actual-data-nodes=ds-$->{0..1}.t_order_item_$->{0..1}
    24. spring.shardingsphere.rules.sharding.tables.t_order_item.table-strategy.standard.sharding-column=order_id
    25. spring.shardingsphere.rules.sharding.tables.t_order_item.table-strategy.standard.sharding-algorithm-name=t-order-item-inline
    26. spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.column=order_item_id
    27. spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.key-generator-name=snowflake
    28. spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.type=INLINE
    29. spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.props.algorithm-expression=ds-$->{user_id % 2}
    30. spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-inline.type=INLINE
    31. spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-inline.props.algorithm-expression=t_order_$->{order_id % 2}
    32. spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-item-inline.type=INLINE
    33. spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-item-inline.props.algorithm-expression=t_order_item_$->{order_id % 2}
    34. spring.shardingsphere.rules.sharding.key-generators.snowflake.type=SNOWFLAKE
    35. spring.shardingsphere.rules.sharding.auditors.shardingKeyAudit.type=DML_SHARDING_CONDITIONS