Purpose
You can use this statement to create a database and specify default attributes of the database, such as the default character set and collation of the database.
CREATE DATABASE is equivalent to CREATE SCHEMA.
Syntax
create_database_stmt:
CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] database_name [database_option_list]
database_option_list:
database_option [database_option ...]
database_option:
[DEFAULT] {CHARACTER SET | CHARSET} [=] charset_name
| [DEFAULT] COLLATE [=] collation_name
| REPLICA_NUM [=] int_num
| {READ ONLY | READ WRITE}
| DEFAULT TABLEGROUP [=] {NULL | table_group_name}
Parameters
| Parameter | Description |
|---|---|
| database_name | The name of the database. |
| [DEFAULT] {CHARACTER SET | CHARSET} charset_name | The character set of the database. The DEFAULT keyword is optional and does not affect the semantics. |
| [DEFAULT] COLLATE collation_name | The collation of the database. The DEFAULT keyword is optional and does not affect the semantics. |
| REPLICA_NUM int_num | The number of replicas. |
| 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
Create a database named
test2and specify the character set asUTF8.obclient> CREATE DATABASE test2 DEFAULT CHARACTER SET UTF8; Query OK, 1 row affectedCreate a database named
test3that supports read and write operations.obclient> CREATE DATABASE test3 READ WRITE; Query OK, 1 row affected