Sharding-Proxy 分库配置

Sharding-Proxy 分库配置,第1张

Sharding-Proxy 分库配置 一 创建两个数据库 

edu_db_1

edu_db_2

二 配置 config-sharding.yaml
schemaName: sharding_db

dataSources:
  ds_0:
    url: jdbc:mysql://127.0.0.1:3306/edu_db_1?serverTimezone=UTC&useSSL=false
    username: root
    password: Mima123456
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
  ds_1:
    url: jdbc:mysql://127.0.0.1:3306/edu_db_2?serverTimezone=UTC&useSSL=false
    username: root
    password: Mima123456
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50

shardingRule:
  tables:
    t_order:
      actualDataNodes: ds_${0..1}.t_order_${1..2}
      tableStrategy:
        inline:
          shardingColumn: order_id
          algorithmexpression: t_order_${order_id % 2 + 1}
      keyGenerator:
        type: SNOWFLAKE
        column: order_id
  bindingTables:
    - t_order
  defaultDatabaseStrategy:
    inline:
      shardingColumn: user_id
      algorithmexpression: ds_${user_id % 2}
  defaultTableStrategy:
    none:
三 启动 Sharding-Proxy 服务 四 打开 cmd ,连接 Sharding-Proxy 服务
C:Userschengqiuming>mysql -P3307 -uroot -p
Enter password: **********
ERROR 1045 (28000): Access denied for user 'root'@'0:0:0:0:0:0:0:1' (using password: YES)

C:Userschengqiuming>mysql -P3307 -uroot -p
Enter password: **********
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.6.4-Sharding-Proxy 4.0.0

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
五 创建数据库表
create table ds_0.t_order(
order_id bigint not null,
user_id int not null,
status varchar(50),
primary key(order_id)
);

此时生成的数据表如下。

 六 插入一条记录
mysql> insert into t_order(order_id,user_id,status) values(11,1,'init');
Query OK, 1 row affected (0.15 sec)

插入数据如下

 

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5482642.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-12
下一篇2022-12-12

发表评论

登录后才能评论

评论列表(0条)

    保存