apache / shardingsphere

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

You have an error in your SQL syntax: ADD RESOURCE #22153

Closed zzsoszz closed 1 year ago

zzsoszz commented 1 year ago

Bug Report

mysql> ADD RESOURCE ds01 ( -> host=127.0.0.1, -> port=13306, -> db="my_database", -> user="root", -> password="my_root_password" -> ) -> ; ERROR 12000 (42000): You have an error in your SQL syntax: ADD RESOURCE ds01 ( host=127.0.0.1, port=13306, db="my_database", user="root", password="my_root_password" ), no viable alternative at input 'ADD' at line 1, position 0, near [@0,0:2='ADD',<78>,1:0]

Which version of ShardingSphere did you use?

mysql> select version();
+-----------------------------------+
| version()                         |
+-----------------------------------+
| 5.7.22-ShardingSphere-Proxy 5.2.1 |
+-----------------------------------+
1 row in set (0.04 sec)

mysql client version

mysql  Ver 8.0.31-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-Proxy

Expected behavior

add resource sucessed;

Actual behavior

no viable alternative at input 'ADD' at line 1, position 0, near [@0,0:2='ADD',<78>,1:0]

Steps to reproduce the behavior, such as: SQL to execute, sharding rule


authority:
  users:
    - user: root
      password: root
    - user: sharding
      password: sharding
  privilege:
    type: ALL_PERMITTED

rules:
  - !TRANSACTION
    defaultType: XA
    providerType: Atomikos
  - !SQL_PARSER
    sqlCommentParseEnabled: true

props:
  max-connections-size-per-query: 1
  kernel-executor-size: 16  # Infinite by default.
  proxy-frontend-flush-threshold: 128  # The default value is 128.
  proxy-hint-enabled: true
  sql-show: false
  check-table-metadata-enabled: false
    # Proxy backend query fetch size. A larger value may increase the memory usage of ShardingSphere Proxy.
  # The default value is -1, which means set the minimum value for different JDBC drivers.
  proxy-backend-query-fetch-size: -1
  proxy-frontend-executor-size: 0 # Proxy frontend executor size. The default value is 0, which means let Netty decide.
    # Available options of proxy backend executor suitable: OLAP(default), OLTP. The OLTP option may reduce time cost of writing packets to client, but it may increase the latency of SQL execution
  # if client connections are more than proxy-frontend-netty-executor-size, especially executing slow SQL.
  proxy-backend-executor-suitable: OLAP
shardingsphere-proxy/bin/start.sh
mysql -h127.0.0.1 -P3307 -uroot -proot
ADD RESOURCE ds01 (
    host=119.23.110.179,
    port=13306,
    db="my_database",
    user="root",
    password="my_root_password"
);
RaigorJiang commented 1 year ago

Hi @zzsoszz host is a string, it needs to be wrapped in quotes.

host="119.23.110.179"

Please refer to the document of DistSQL: https://shardingsphere.apache.org/document/5.2.1/en/user-manual/shardingsphere-proxy/distsql/syntax/rdl/resource-definition/

RaigorJiang commented 1 year ago

@zzsoszz I think the issue has been solved, I will close it.