Resource Definition

Syntax

  1. ADD RESOURCE resourceDefinition [, resourceDefinition] ...
  2. ALTER RESOURCE resourceDefinition [, resourceDefinition] ...
  3. DROP RESOURCE resourceName [, resourceName] ... [ignore single tables]
  4. resourceDefinition:
  5. simpleSource | urlSource
  6. simpleSource:
  7. resourceName(HOST=hostname,PORT=port,DB=dbName,USER=user [,PASSWORD=password] [,PROPERTIES(property [,property]) ...])
  8. urlSource:
  9. resourceName(URL=url,USER=user [,PASSWORD=password] [,PROPERTIES(property [,property]) ...])
  10. property:
  11. key=value

Parameters Explained

NameDataTypeDescription
resourceNameIDENTIFIERResource name
hostnameSTRINGHost or IP
portINTPort
dbNameSTRINGDB name
urlSTRINGURL
userSTRINGusername
passwordSTRINGpassword

Notes

  • Before adding resources, please confirm that a distributed database has been created, and execute the use command to successfully select a database;
  • Confirm that the resource to be added or altered can be connected, otherwise the operation will not be successful;
  • Duplicate resourceName is not allowed;
  • PROPERTIES is used to customize connection pool parameters, key and value are both STRING types;
  • ALTER RESOURCE is not allowed to change the real data source associated with this resource;
  • ALTER RESOURCE will switch the connection pool. This operation may affect the ongoing business, please use it with caution;
  • DROP RESOURCE will only delete logical resources, not real data sources;
  • Resources referenced by rules cannot be deleted;
  • If the resource is only referenced by single table rule, and the user confirms that the restriction can be ignored, the optional parameter ignore single tables can be added to perform forced deletion.

Example

  1. ADD RESOURCE resource_0 (
  2. HOST="127.0.0.1",
  3. PORT=3306,
  4. DB="db0",
  5. USER="root",
  6. PASSWORD="root"
  7. ),resource_1 (
  8. HOST="127.0.0.1",
  9. PORT=3306,
  10. DB="db1",
  11. USER="root"
  12. ),resource_2 (
  13. HOST="127.0.0.1",
  14. PORT=3306,
  15. DB="db2",
  16. USER="root",
  17. PROPERTIES("maximumPoolSize"="10")
  18. ),resource_3 (
  19. URL="jdbc:mysql://127.0.0.1:3306/db3?serverTimezone=UTC&useSSL=false",
  20. USER="root",
  21. PASSWORD="root",
  22. PROPERTIES("maximumPoolSize"="10","idleTimeout"="30000")
  23. );
  24. ALTER RESOURCE resource_0 (
  25. HOST="127.0.0.1",
  26. PORT=3309,
  27. DB="db0",
  28. USER="root",
  29. PASSWORD="root"
  30. ),resource_1 (
  31. URL="jdbc:mysql://127.0.0.1:3309/db1?serverTimezone=UTC&useSSL=false",
  32. USER="root",
  33. PASSWORD="root",
  34. PROPERTIES("maximumPoolSize"="10","idleTimeout"="30000")
  35. );
  36. DROP RESOURCE resource_0, resource_1;
  37. DROP RESOURCE resource_2, resource_3 ignore single tables;