# sharding-jdbc 水平分库分表策略
# 配置数据源,给数据源起别名
# 水平分库需要配置多个数据库
spring.shardingsphere.datasource.names=m1,f1,f2,f3,f4,f5
spring.shardingsphere.sharding.binding-tables=flight_record
# 一个实体类对应两张表,覆盖
spring.main.allow-bean-definition-overriding=true
## 配置第一个数据源的具体内容,包含连接池,驱动,地址,用户名,密码 主数据源
spring.shardingsphere.datasource.m1.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.m1.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.m1.url=jdbc:mysql://基础库:3306/库名?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
spring.shardingsphere.datasource.m1.username=root
spring.shardingsphere.datasource.m1.password=123456
# 配置第二个数据源的具体内容,包含连接池,驱动,地址,用户名,密码
spring.shardingsphere.datasource.f1.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.f1.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.f1.url=jdbc:mysql://数据库地址:3306/库名?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
spring.shardingsphere.datasource.f1.username=root
spring.shardingsphere.datasource.f1.password=123456
# 配置第三个数据源的具体内容,包含连接池,驱动,地址,用户名,密码
spring.shardingsphere.datasource.f2.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.f2.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.f2.url=jdbc:mysql://数据库地址:3306/库名?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
spring.shardingsphere.datasource.f2.username=root
spring.shardingsphere.datasource.f2.password=123456
# 配置第三个数据源的具体内容,包含连接池,驱动,地址,用户名,密码
spring.shardingsphere.datasource.f3.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.f3.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.f3.url=jdbc:mysql://数据库地址:3306/库名?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
spring.shardingsphere.datasource.f3.username=root
spring.shardingsphere.datasource.f3.password=123456
# 配置第四个数据源的具体内容,包含连接池,驱动,地址,用户名,密码
spring.shardingsphere.datasource.f4.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.f4.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.f4.url=jdbc:mysql://数据库地址:3306/库名?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
spring.shardingsphere.datasource.f4.username=root
spring.shardingsphere.datasource.f4.password=123456
# 配置第五个数据源的具体内容,包含连接池,驱动,地址,用户名,密码
spring.shardingsphere.datasource.f5.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.f5.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.f5.url=jdbc:mysql://数据库地址:3306/库名?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
spring.shardingsphere.datasource.f5.username=root
spring.shardingsphere.datasource.f5.password=123456
# 指定数据库分布的情况和数据表分布的情况
# m1 m2 flight_record flight_record
spring.shardingsphere.sharding.tables.flight_record.actual-data-nodes=f$->{1..5}.flight_record
# 指定 flight_record 表里面主键 id 的生成策略 SNOWFLAKE
spring.shardingsphere.sharding.tables.flight_record.key-generator.column=id
spring.shardingsphere.sharding.tables.flight_record.key-generator.type=SNOWFLAKE
# 指定分库策略 约定 analyse_id 值偶数添加到 m1 库,如果 tenant_id 是奇数添加到 m2 库
# 默认写法(所有的表的tenant_id)
spring.shardingsphere.sharding.tables.flight_record.database-strategy.inline.sharding-column=analyse_id
spring.shardingsphere.sharding.tables.flight_record.database-strategy.inline.algorithm-expression=f$->{analyse_id % 5 + 1}
#default-data-source-name: m1 #对于其他业务表设置默认数据源
spring.shardingsphere.sharding.default-data-source-name=m1
# 打开 sql 输出日志
spring.shardingsphere.props.sql.show=true