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 | Specifies the name of the database whose properties are to be modified. If not specified, the current database will be modified. If the current database is empty, an error will be returned. |
| [DEFAULT] { CHARACTER SET | CHARSET } charset_name | Specifies the default character set for the database. CHARACTER SET and CHARSET are synonyms. The DEFAULT keyword is optional and does not affect the semantics. |
| [DEFAULT] COLLATE collation_name | Specifies the default collation for the database. The DEFAULT keyword is optional and does not affect the semantics. |
| READ ONLY | READ WRITE | Sets the read-only or read-write property at the database level. |
| [DEFAULT] TABLEGROUP table_group_name | Sets the default table group for the database. NULL indicates that the default table group for the database will be canceled.
NoteFor V4.4.x versions, starting from V4.4.1, executing this command will actually modify the TableGroup property 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 property of a database, the system will 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 it 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;