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
PRIMARY_ZONE [=] zone_name
{READ ONLY READ WRITE}
DEFAULT TABLEGROUP [=] {NULL table_group_name}
Parameters
| Parameter | Description |
|---|---|
| database_name | Specifies the name of the database whose attributes are to be modified. |
| [DEFAULT] {CHARACTER SET CHARSET} charset_name | Specifies the character set to be modified. The DEFAULT keyword is optional and does not affect the semantics. |
| [DEFAULT] COLLATE collation_name | Specifies the collation. The DEFAULT keyword is optional and does not affect the semantics. |
| REPLICA_NUM int_num | Specifies the number of replicas. |
| PRIMARY_ZONE zone_name | Specifies the primary zone of the database. |
| READ ONLY READ WRITE | Specifies the read-only or read/write attribute of the database. |
| DEFAULT TABLEGROUP table_group_name | Specifies 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 affected (0.00 sec)Create a database named
test3that supports read and write operations.obclient> CREATE DATABASE test3 READ WRITE; Query OK, 1 row affected (0.03 sec)