apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.89k stars 6.73k forks source link

ERROR 1046 (3D000): No database selected when create table if not exists ds_0.t_order #29374

Closed 4RSENALZ closed 3 months ago

4RSENALZ commented 10 months ago

ds_0 Even thought I've "use sharding_db", I still get ERROR 1046 It seems like my datasource named ds_0 wasn't created successfully? If I use " create table if not exists t_order(order_id BIGINT NOT NULL,user_id INT NOT NULL,status VARCHAR(50),PRIMARY KEY (order_id));" ,then the table can be successfully created, but it is created in the sharding_db, not in the demo_ds_0 shardingdb

My config-sharding.yaml:

databaseName: sharding_db

dataSources:
  ds_0:
    url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
    username: root
    password: root
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1

rules:
- !SHARDING
  tables:
    t_order:
      actualDataNodes: ds_${0}.t_order_${0..1}
      tableStrategy:
        standard:
          shardingColumn: order_id
          shardingAlgorithmName: t_order_inline
      keyGenerateStrategy:
        column: order_id
        keyGeneratorName: snowflake
      auditStrategy:
        auditorNames:
          - sharding_key_required_auditor
        allowHintDisable: true

  bindingTables:
    - t_order
  defaultDatabaseStrategy:
    standard:
      shardingColumn: user_id
      shardingAlgorithmName: database_inline
  defaultTableStrategy:
    none:
  defaultAuditStrategy:
    auditorNames:
      - sharding_key_required_auditor
    allowHintDisable: true

  shardingAlgorithms:
    database_inline:
      type: INLINE
      props:
        algorithm-expression: ds_${0}
    t_order_inline:
      type: INLINE
      props:
        algorithm-expression: t_order_${0}

  keyGenerators:
    snowflake:
      type: SNOWFLAKE

  auditors:
    sharding_key_required_auditor:
      type: DML_SHARDING_CONDITIONS

- !BROADCAST
  tables:
    - t_address

My databases: demo_ds_0 Pls can someone help me to solve this problem

github-actions[bot] commented 9 months ago

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.

terrymanu commented 3 months ago

What is the version?

github-actions[bot] commented 3 months ago

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.