yangzan66 opened a new issue, #21251:
URL: https://github.com/apache/shardingsphere/issues/21251

   the log reports error when using shardingsphere-proxy,  the mysql username 
and password are really correct.
   
   version: apache-shardingsphere-5.2.0-shardingsphere-proxy
   
   connect to sharding-proxy and operate:
   mysql> show databases;
   +--------------------+
   | schema_name        |
   +--------------------+
   | information_schema |
   | performance_schema |
   | topsql             |
   | mysql              |
   | sys                |
   +--------------------+
   5 rows in set (0.01 sec)
   
   mysql> use topsql;
   Reading table information for completion of table and column names
   You can turn off this feature to get a quicker startup with -A
   
   Database changed
   mysql> create table topsqltable(id bigint(4),c1 varchar(200));
   ERROR 30000 (HY000): Unknown exception: Can not get connection from 
datasource topsql_0.
   mysql>
   
   the error log as below:
   [ERROR] 2022-09-28 21:00:47.104 [ShardingSphere-Command-1] 
o.a.s.p.f.c.CommandExecutorTask - Exception occur:
   java.lang.NullPointerException: Can not get connection from datasource 
topsql_0.
        at 
com.google.common.base.Preconditions.checkNotNull(Preconditions.java:987)
        at 
org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCBackendDataSource.getConnections(JDBCBackendDataSource.java:77)
        at 
org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCBackendDataSource.getConnections(JDBCBackendDataSource.java:52)
        at 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection.createNewConnections(JDBCBackendConnection.java:96)
        at 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection.getConnections(JDBCBackendConnection.java:87)
        at 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.DriverExecutionPrepareEngine.group(DriverExecutionPrepareEngine.java:88)
        at 
org.apache.shardingsphere.infra.executor.sql.prepare.AbstractExecutionPrepareEngine.prepare(AbstractExecutionPrepareEngine.java:62)
        at 
org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.useDriverToExecute(ProxySQLExecutor.java:187)
        at 
org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.execute(ProxySQLExecutor.java:153)
        at 
org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.execute(ProxySQLExecutor.java:147)
        at 
org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.execute(JDBCDatabaseCommunicationEngine.java:132)
        at 
org.apache.shardingsphere.proxy.backend.handler.admin.mysql.executor.UnicastResourceShowExecutor.execute(UnicastResourceShowExecutor.java:86)
        at 
org.apache.shardingsphere.proxy.backend.handler.admin.DatabaseAdminQueryBackendHandler.execute(DatabaseAdminQueryBackendHandler.java:56)
        at 
org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:94)
        at 
org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:110)
        at 
org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:77)
        at 
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at 
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)
   
   ------------------------------------
   the config file config-sharding.yaml as follow:
   
   databaseName: topsql
   dataSources:
     ds_0:
       url: 
jdbc:mysql://10.20.26.1xx:3306/topsql_0?serverTimezone=UTC&useSSL=false
       username: shard
       password: 1mMxmuB6Odu
       connectionTimeoutMilliseconds: 30000
       idleTimeoutMilliseconds: 60000
       maxLifetimeMilliseconds: 1800000
       maxPoolSize: 50
       minPoolSize: 1
     ds_1:
       url: 
jdbc:mysql://10.20.26.1xx:3306/topsql_1?serverTimezone=UTC&useSSL=false
       username: shard
       password: 1mMxmuB6Odu
       connectionTimeoutMilliseconds: 30000
       idleTimeoutMilliseconds: 60000
       maxLifetimeMilliseconds: 1800000
       maxPoolSize: 50
       minPoolSize: 1
   rules:
   - !SHARDING
     tables:
       # 逻辑表的名字
       topsqltable:
         # 由数据源名 + 表名组成(参考 Inline 语法规则)
         actualDataNodes: topsql_${0..1}.topsqltable_${0..2}
         # 分表策略
         tableStrategy:
           standard:
             # 分片键
             shardingColumn: id
             # 使用哪个分片策略
             shardingAlgorithmName: topsqltable_inline
         # 主键生成策略
         keyGenerateStrategy:
           column: id
           keyGeneratorName: snowflake
     defaultDatabaseStrategy:
       standard:
         shardingColumn: id
         shardingAlgorithmName: database_inline
     shardingAlgorithms:
       # 分库的默认策略
       database_inline:
         type: INLINE
         props:
           # 数据库分片规则, id取模2,结果有 0 和 1,路由到 0 和 1这两个数据库
           algorithm-expression: topsql_${id % 2}
      # 分表使用的策略的名字
       topsqltable_inline:
         type: INLINE
         props:
           #  表的分片规则, 
id取模3,结果有0,1,2,得到topsqltable_0,topsqltable_1,topsqltable_2这三张表
           algorithm-expression: topsqltable_${id % 3}
     keyGenerators:
       snowflake:
         type: SNOWFLAKE


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to