CREATE DB_DISCOVERY RULE

Description

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

Syntax

  1. CreateDatabaseDiscoveryRule ::=
  2. 'CREATE' 'DB_DISCOVERY' 'RULE' ( databaseDiscoveryDefinition | databaseDiscoveryConstruction ) ( ',' ( databaseDiscoveryDefinition | databaseDiscoveryConstruction ) )*
  3. databaseDiscoveryDefinition ::=
  4. ruleName '(' 'RESOURCES' '(' resourceName ( ',' resourceName )* ')' ',' 'TYPE' '(' 'NAME' '=' typeName ( ',' 'PROPERTIES' 'key' '=' 'value' ( ',' 'key' '=' 'value' )* )? ',' 'HEARTBEAT' '(' 'key' '=' 'value' ( ',' 'key' '=' 'value' )* ')' ')'
  5. databaseDiscoveryConstruction ::=
  6. ruleName '(' 'RESOURCES' '(' resourceName ( ',' resourceName )* ')' ',' 'TYPE' '=' discoveryTypeName ',' 'HEARTBEAT' '=' discoveryHeartbeatName ')'
  7. ruleName ::=
  8. identifier
  9. resourceName ::=
  10. identifier
  11. typeName ::=
  12. identifier
  13. discoveryHeartbeatName ::=
  14. identifier

Supplement

  • discoveryType specifies the database discovery service type, ShardingSphere has built-in support for MySQL.MGR;
  • Duplicate ruleName will not be created.

Example

When creating a discoveryRule, create both discoveryType and discoveryHeartbeat

  1. CREATE
  2. DB_DISCOVERY RULE db_discovery_group_0 (
  3. RESOURCES(ds_0, ds_1, ds_2),
  4. TYPE(NAME='MySQL.MGR',PROPERTIES('group-name'='92504d5b-6dec')),
  5. HEARTBEAT(PROPERTIES('keep-alive-cron'='0/5 * * * * ?'))
  6. );

Use the existing discoveryType and discoveryHeartbeat to create a discoveryRule

  1. CREATE
  2. DB_DISCOVERY RULE db_discovery_group_1 (
  3. RESOURCES(ds_0, ds_1, ds_2),
  4. TYPE=db_discovery_group_1_mgr,
  5. HEARTBEAT=db_discovery_group_1_heartbeat
  6. );

Reserved word

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