Purpose
You can use this statement to modify the attributes of a database.
Syntax
ALTER {DATABASESCHEMA} [database_name] [SET] alter_specification [alter_specification ...];
alter_specification:
[DEFAULT] {CHARACTER SET CHARSET} [=] charset_name
[DEFAULT] COLLATE [=] collation_name
PRIMARY_ZONE [=] zone_name
{READ ONLY READ WRITE}
DEFAULT TABLEGROUP [=] {NULL table_group_name}
Parameters
| Parameter | Description |
|---|---|
| database_name | Specifies the name of the database whose attributes are to be modified. If this parameter is not specified, the current database is to be modified. If the current database is empty, an error is returned. |
| [DEFAULT] { CHARACTER SET CHARSET } charset_name | Specifies the default character set of the database. CHARACTER SET is equivalent to CHARSET. The DEFAULT keyword is optional and does not affect the semantics. |
| [DEFAULT] COLLATE collation_name | Specifies the default collation of the database. The DEFAULT keyword is optional and does not affect the semantics. |
| PRIMARY_ZONE zone_name | Specifies the primary zone of the database. By default, the value is the same as that of the tenant. Full-featured replicas in the region to which the specified zone belongs must be the majority of replicas. Otherwise, ERROR 4179 is returned. |
| READ ONLY READ WRITE | Specifies the read-only or read/write attribute of the database. |
| DEFAULT TABLEGROUP table_group_name | Specifies the default table group of the database. When you set it to NULL, the system disables the default table group. |
Examples
Change the character set of database test2 to UTF8MB4, set the database collation to UTF8MB4_BIN, and set the database read/write attribute to Read and Write.
obclient> ALTER DATABASE test2 DEFAULT CHARACTER SET utf8mb4;
Query OK, 0 rows affected (0.03 sec)
obclient> ALTER DATABASE test2 DEFAULT COLLATE utf8mb4_bin;
Query OK, 0 rows affected (0.03 sec)
obclient> ALTER DATABASE test2 READ WRITE;
Query OK, 0 rows affected (0.02 sec)