Purpose
This statement is used to modify the properties of a database.
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
| Parameter | Description |
|---|---|
| database_name | The name of the database whose properties you want to modify. If you do not specify this parameter, the properties of the current database are modified. If the current database does not exist, an error is returned. |
| [DEFAULT] { CHARACTER SET | CHARSET } charset_name | The default character set of the database. CHARACTER SET and CHARSET are synonyms. The DEFAULT keyword is optional and does not affect the semantics. |
| [DEFAULT] COLLATE collation_name | The default collation of the database. The DEFAULT keyword is optional and does not affect the semantics. |
| READ ONLY | READ WRITE | The read-only or read/write attribute of the database. |
| [DEFAULT] TABLEGROUP table_group_name | The default table group of the database. NULL indicates that the default table group of the database is canceled.
NoteFor V4.4.x versions, starting from V4.4.1, executing this command will modify the TableGroup attribute of all tables under the database. For more information about the aggregation of user tables under a database, see Aggregation of user tables under a database. After modifying the TableGroup attribute of a database, the system does not immediately align 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 the test2 database to UTF8MB4, the collation to UTF8MB4_BIN, and set the database 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;
