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 current database will be modified. If the current database does not exist, an error will be 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 will be canceled. When you change the default table group (DEFAULT TABLEGROUP) of the database, existing tables will not be automatically migrated to the new default table group. |
| The new default table group setting will only be applied when you create a new table and do not specify a table group when creating the table. |
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;
Query OK, 0 rows affected
obclient> ALTER DATABASE test2 DEFAULT COLLATE utf8mb4_bin;
Query OK, 0 rows affected
obclient> ALTER DATABASE test2 READ WRITE;
Query OK, 0 rows affected