CREATE DB_DISCOVERY RULE

Description

The CREATE DB_DISCOVERY RULE syntax is used to create a database discovery rule.

Syntax

Grammar Railroad diagram

  1. CreateDatabaseDiscoveryRule ::=
  2. 'CREATE' 'DB_DISCOVERY' 'RULE' ifNotExists? databaseDiscoveryDefinition (',' databaseDiscoveryDefinition)*
  3. ifNotExists ::=
  4. 'IF' 'NOT' 'EXISTS'
  5. databaseDiscoveryDefinition ::=
  6. ruleName '(' 'STORAGE_UNITS' '(' storageUnitName (',' storageUnitName)* ')' ',' 'TYPE' '(' 'NAME' '=' typeName (',' propertiesDefinition)? ')' ',' 'HEARTBEAT' '(' propertiesDefinition ')' ')'
  7. propertiesDefinition ::=
  8. 'PROPERTIES' '(' key '=' value (',' key '=' value)* ')'
  9. ruleName ::=
  10. identifier
  11. storageUnitName ::=
  12. identifier
  13. typeName ::=
  14. identifier
  15. discoveryHeartbeatName ::=
  16. identifier
  17. key ::=
  18. string
  19. value ::=
  20. literal

Supplement

  • discoveryType specifies the database discovery service type, ShardingSphere has built-in support for MySQL.MGR;
  • Duplicate ruleName will not be created;
  • ifNotExists clause used for avoid Duplicate db_discovery rule error.

Example

  • Create database discovery rule
  1. CREATE DB_DISCOVERY RULE db_discovery_group_0 (
  2. STORAGE_UNITS(ds_0, ds_1, ds_2),
  3. TYPE(NAME='MySQL.MGR',PROPERTIES('group-name'='92504d5b-6dec')),
  4. HEARTBEAT(PROPERTIES('keep-alive-cron'='0/5 * * * * ?'))
  5. );
  • Create database discovery rule with ifNotExists clause
  1. CREATE DB_DISCOVERY RULE IF NOT EXISTS db_discovery_group_0 (
  2. STORAGE_UNITS(ds_0, ds_1, ds_2),
  3. TYPE(NAME='MySQL.MGR',PROPERTIES('group-name'='92504d5b-6dec')),
  4. HEARTBEAT(PROPERTIES('keep-alive-cron'='0/5 * * * * ?'))
  5. );

Reserved word

CREATE, DB_DISCOVERY, RULE, STORAGE_UNITS, TYPE, NAME, PROPERTIES, HEARTBEAT