sharding-jdbc.yml 1.0 KB

1234567891011121314151617181920212223242526272829
  1. # 数据源配置:支持多数据源(即支持分库)
  2. dataSources:
  3. ds_0:
  4. driverClassName: com.mysql.cj.jdbc.Driver
  5. dataSourceClassName: com.zaxxer.hikari.HikariDataSource
  6. jdbcUrl: jdbc:mysql://192.168.36.128:3306/webchat_ugc?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2b8&allowPublicKeyRetrieval=true
  7. username: root
  8. password: 12345678
  9. # 分库分表规则配置
  10. rules:
  11. - !SINGLE
  12. defaultDataSource: ds_0
  13. tables:
  14. - ds_0.* # 声明 ds_0 下所有表为单表
  15. - !SHARDING
  16. tables:
  17. web_chat_moment_timeline:
  18. actualDataNodes: ds_0.web_chat_moment_timeline_${0..2}
  19. tableStrategy:
  20. standard:
  21. shardingColumn: user_id
  22. shardingAlgorithmName: timeline_table_hash_mod
  23. shardingAlgorithms:
  24. timeline_table_hash_mod:
  25. type: CLASS_BASED
  26. props:
  27. strategy: STANDARD
  28. algorithmClassName: com.webchat.ugc.config.shardingJdbc.CustomHashModShardingAlgorithm
  29. sharding-count: 3