Skip to content

shardingsphere insert statement error : Route table does not exist #33784

@BroFanta

Description

@BroFanta

Question

I first set up MySQL on port 3306 and created a database named dis_database0. Then, I set up MySQL2 on port 3308 and created another database named dis_database1. After that, I used ShardingSphere (port 3307) to connect these two databases. When I created the table HuangHStu in ShardingSphere, corresponding sharded tables were automatically generated in both databases. However, when executing an INSERT statement, an error occurs. Please help me resolve this issue.

Version information

shardingsphere:apache-shardingsphere-5.4.1
mysql:8.0.40

config-sharding.yaml

databaseName: sharding_db
 
dataSources:
  ds_0:
    url: jdbc:mysql://127.0.0.1:3306/dis_database0?serverTimezone=UTC&useSSL=false
    username: root
    password: root
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
  ds_1:
    url: jdbc:mysql://127.0.0.1:3308/dis_database1?serverTimezone=UTC&useSSL=false
    username: root
    password: root
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
rules:
- !SHARDING
  tables:
    HuangHStu:
      actualDataNodes: ds_${0..1}.HuangHStu
      tableStrategy:
        standard:
          shardingColumn: Sno
          shardingAlgorithmName: Sno_inline
    HuangHSC:
      actualDataNodes: ds_${0..1}.HuangHSC
      tableStrategy:
        standard:
          shardingColumn: Sno
          shardingAlgorithmName: Sno_inline
  bindingTables:
    - HuangHStu,HuangHSC
  defaultDatabaseStrategy:
    none:
  defaultTableStrategy:
    none:
  shardingAlgorithms:
    Sno_inline:
      type: INLINE
      props:
        algorithm-expression: ds_${(Sno % 2).abs()}
- !BROADCAST
  tables:
   - HuangHCou

Series of operations

I executed the following CREATE TABLE operation in sharding_db.

CREATE TABLE if not exists HuangHStu (
    Sno INT PRIMARY KEY,          -- 学号,主键,长度最多为6
    Sname VARCHAR(50) NOT NULL,         -- 姓名,不允许为空
    Sdept VARCHAR(100),                 -- 学院
    Stel VARCHAR(15),                   -- 联系方式,建议格式为手机或电话号码
    Sex CHAR(1) CHECK (Sex IN ('M', 'F')), -- 性别,仅允许 'M'(男)或 'F'(女)
    Sage INT, -- 年龄,范围在 0-150
    Saddr VARCHAR(200),                 -- 家庭住址
    Spost VARCHAR(10)                   -- 邮编
);

The subsequent database state is shown in the image.
image
image
Next, I executed the following INSERT operation in HuangHStu within sharding_db.

INSERT INTO HuangHStu (Sno, Sname, Sdept, Stel, Sex, Sage, Saddr, Spost)
VALUES 
(100001, '张三', '计算机学院', '13812345678', 'M', 20, '四川省成都市青羊区', '610000');

An error occurred while executing the INSERT operation.

Error details

image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions