Description
You can execute the CREATE DATABASE statement to create a database. You can also specify default attributes for a database, such as the default character set and collation of the database.
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 | The name of the database for which you want to modify attributes. By default, the current database is modified if you leave this parameter empty. |
| CHARSET charset_name | The character set that you want to modify. |
| COLLATE collation_name | The collation. |
| REPLICA_NUM int_num | The number of replicas. |
| PRIMARY_ZONE zone_name | The primary zone. |
| READ ONLY | READ WRITE | The attribute of the database. Valid values: READ ONLY and READ WRITE. |
| DEFAULT TABLEGROUP table_group_name | The default table group of the database. A NULL value specifies no default table group for the database. |
Examples
- Create the test2 database that uses the UTF-8 character set.
OceanBase(admin@test)>create database test2 default CHARACTER SET UTF8;
Query OK, 1 row affected (0.00 sec)
- Create the test3 database in read/write mode.
OceanBase(admin@test)>create database test3 READ WRITE;
Query OK, 1 row affected (0.03 sec)