ShardingSphere-JDBC 是一个工作在客户端的,定位为轻量级 Java 框架,在 Java 的 JDBC 层提供的额外服务。可以将任意数据库转换为分布式数据库,并通过数据分片、弹性伸缩、加密等能力对原有数据库进行增强。
mybatis:
type-aliases-package=com.xiaohei.sharding.verticaldatabase.mapper
spring:
shardingsphere:
datasource:
names: ds1,ds2
ds1:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://localhost:3306/sharding_sphere_01?serverTimezone=UTC
username: root
password: 123456
ds2:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://localhost:3306/sharding_sphere_02?serverTimezone=UTC
username: root
password: 123456
sharding:
tables:
order:
actual-data-nodes: ds1.order
# key-generator:
# column: id
# type: SNOWFLAKE
# table-strategy:
# inline:
# sharding-column: id
# algorithm-expression: order
customer:
actual-data-nodes: ds2.customer
# key-generator:
# column: id
# type: SNOWFLAKE
# table-strategy:
# inline:
# sharding-column: id
# algorithm-expression: customer
props:
sql:
show: true
mybatis:
type-aliases-package=com.xiaohei.sharding.horizontaldatabase.mapper
spring:
shardingsphere:
datasource:
names: ds1,ds2
ds1:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://localhost:3306/sharding_sphere_01?serverTimezone=UTC
username: root
password: 123456
ds2:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://localhost:3306/sharding_sphere_02?serverTimezone=UTC
username: root
password: 123456
sharding:
tables:
order:
actual-data-nodes: ds$->{1..2}.orders_$->{1..2}
key-generator:
column: id
type: MyAtomicLong
props:
worker:
id: 1000
table-strategy:
inline:
sharding-column: id
algorithm-expression: orders_$->{id%2+1}
database-strategy:
inline:
sharding-column: customer_id
algorithm-expression: ds$->{customer_id%2+1}
props:
sql:
show: true
mybatis:
type-aliases-package=com.xiaohei.sharding.horizontaltable.mapper
spring:
shardingsphere:
datasource:
names: ds1
ds1:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://localhost:3306/sharding_sphere?serverTimezone=UTC
username: root
password: 123456
sharding:
tables:
order:
actual-data-nodes: ds1.orders_$->{1..2}
key-generator:
column: id
type: SNOWFLAKE
table-strategy:
inline:
sharding-column: id
algorithm-expression: orders_$->{id%2+1}
props:
sql:
show: true
shardingsphere-jdbc默认使用的事务类型为本地事务(LOCAL)
mybatis:
type-aliases-package=com.xiaohei.sharding.readwritesplitting.mapper
spring:
shardingsphere:
datasource:
names: ds1,ds2
ds1:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://localhost:3306/sharding_sphere_01?serverTimezone=UTC
username: root
password: 123456
ds2:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://localhost:3306/sharding_sphere_02?serverTimezone=UTC
username: root
password: 123456
masterslave:
name: ms
master-data-source-name: ds1
slave-data-source-names: ds2
props:
sql:
show: true