ALTER DATABASE
Description
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}
Parameters
| Parameter | Description |
|---|---|
| database_name | The name of the database whose properties are to be modified. If this parameter is not specified, the current database is 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 equivalent. 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. |
Examples
Change the character set of database test2 to UTF8MB4, the collation to UTF8MB4_BIN, and set the database to read/write.
ALTER DATABASE test2 DEFAULT CHARACTER SET utf8mb4;
ALTER DATABASE test2 DEFAULT COLLATE utf8mb4_bin;
ALTER DATABASE test2 READ WRITE;