Sharding Proxy 5.5 单机配置记录


版本

Sharding Proxy 5.5

配置

global.yaml

mode:
  type: Standalone
  repository:
    type: JDBC
authority:
 users:
   - user: root@%
     password: root
   - user: sharding
     password: sharding
 privilege:
   type: ALL_PERMITTED

database-sharding.yaml

databaseName: sharding_db
dataSources:
 ds_0:
   url: jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useOldAliasMetadataBehavior=true
   username: root
   password: 123456
   connectionTimeoutMilliseconds: 30000
   idleTimeoutMilliseconds: 60000
   maxLifetimeMilliseconds: 1800000
   maxPoolSize: 50
   minPoolSize: 1
rules:
- !SHARDING
  tables:
    t_user:
      actualDataNodes: ds_0.t_user_${0..1}
      tableStrategy:
        standard:
          shardingColumn: user_id
          shardingAlgorithmName: t_user_inline
      keyGenerateStrategy:
        column: user_id
        keyGeneratorName: snowflake
  bindingTables:
    - t_user
  defaultDatabaseStrategy:
    none:
  defaultTableStrategy:
    none:
  shardingAlgorithms:
    t_user_inline:
      type: INLINE
      props:
        algorithm-expression: t_user_${user_id % 2}
  keyGenerators:
    snowflake:
      type: SNOWFLAKE

运行

./bin/start.sh

初始化表

CREATE TABLE `t_user_0` (
        `id` bigint (20) NOT NULL,
        `user_id` bigint (20) NOT NULL,
        `create_date` datetime DEFAULT NULL,
        PRIMARY KEY (`id`));
CREATE TABLE `t_user_1` (
        `id` bigint (20) NOT NULL,
        `user_id` bigint (20) NOT NULL,
        `create_date` datetime DEFAULT NULL,
        PRIMARY KEY (`id`));

插入数据

INSERT INTO t_user (id, user_id, create_date) values(1, 1, '2021-01-01 00:00:00'), (2, 2, '2021-01-01 00:00:00'), (3, 3, '2021-01-01 00:00:00'), (4, 4, '2022-01-01 00:00:00'), (5, 5, '2022-02-01 00:00:00'), (6, 6, '2022-03-01 00:00:00');

查看数据

sharding_db.t_user

origin_db.t_user_0

origin_db.t_user_1


前一篇:
后一篇:

发表评论