Purpose
You can use this statement to modify the attributes 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. 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 | 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 | 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. 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 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