MySQL - DROP RESOURCE GROUP Statement



In MySQL you can create resource groups and assign threads to these groups. These threads execute based on the availability of the resources in the group i.e. the group attributes controls the resources and the threads in the group are restricted to the available resources.

MySQL provides various statements to create, alter, drop a group resource and assign threads to a group resource.

DROP RESOURCE GROUP Statement

You can drop/delete an existing resource group using the MySQL DROP RESOURCE GROUP Statement. You need RESOURCE_GROUP_ADMIN privileges to execute the statement.

Syntax

Following is the syntax of the MySQL DROP RESOURCE GROUP Statement −

CREATE RESOURCE GROUP group_name
   TYPE = {SYSTEM|USER}
   [VCPU [=] vcpu_spec [, vcpu_spec] ...]
   [THREAD_PRIORITY [=] N]
   [ENABLE|DISABLE]

Where, group_name is the name of the group you need to delete.

Example

Assume we have created a resource group using the CREATE RESOURCE GROUP statement as shown below −

CREATE RESOURCE GROUP test_group TYPE = USER 
VCPU = 0 THREAD_PRIORITY = 2 DISABLE;

Following query drops/ deletes the above created resource group −

DROP RESOURCE GROUP test_group;

If you try drop a resource group that does not exist an error is generated as follows −

DROP RESOURCE GROUP none;
ERROR 3651 (HY000): Resource Group 'none' does not exist.

The FORCE clause

While deleting an existing resource group if it contains threads, an error will be generated. In such cases if you use the FORCE clause the threads of the group are moved to the default groups and then the group will be deleted.

Example

Assume we have created a resource group as shown below −

CREATE RESOURCE GROUP sample TYPE = USER;

And if we have assigned the current thread to the above created resource group as −

SET RESOURCE GROUP sample;

Now, if you try to remove the resource group sample with out using the FORCE clause an error will be generated as shown below −

DROP RESOURCE GROUP sample;
ERROR 3656 (HY000): Resource group sample is busy.

If you use the FORCE clause the resource group will be deleted without an error (though it contains resources).

DROP RESOURCE GROUP sample FORCE;
Advertisements