Description
This statement is used to modify database attributes.
Syntax
ALTER {DATABASE|SCHEMA} [database_name] [SET] alter_specification [alter_specification ...];
alter_specification:
[DEFAULT] {CHARACTER SET | CHARSET} [=] charset_name
| [DEFAULT] COLLATE [=] collation_name
| {READ ONLY | READ WRITE}
| [DEFAULT] TABLEGROUP [=] {NULL | table_group_name}
Parameters
Parameters |
Description |
|---|---|
| database_name | Specifies the name of the database whose attribute is to be modified. If not specified, the current database will 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. The value must be one of the following: CHARACTER SET and CHARSET Synonym. DEFAULT Keywords are optional and do not affect semantics. |
| [DEFAULT] COLLATE collation_name | Specifies the default collation for the database. DEFAULT Keywords are optional and do not affect semantics. |
| READ ONLY \ | READ WRITE | Sets the database to read-only or read/write. |
| [DEFAULT] TABLEGROUP table_group_name | Sets the default table group information for the database. NULL indicates to cancel the default table group of the database.
NoteWhen you execute this command, the TableGroup attribute of all tables under the database is actually modified. For information about the aggregation of user tables under a database, see Aggregate user tables under a database. After the TableGroup attribute of a database is modified, the system does not immediately align the partitions of all user tables to the same log stream. If you want to aggregate user tables as soon as possible:
|
Examples
Modify the character set of database test2 to UTF8MB4, the collation to UTF8MB4_BIN, and set its access type to read/write.
obclient> ALTER DATABASE test2 DEFAULT CHARACTER SET utf8mb4;
obclient> ALTER DATABASE test2 DEFAULT COLLATE utf8mb4_bin;
obclient> ALTER DATABASE test2 READ WRITE;