CREATE DATABASE

2023-07-28 02:55:42  Updated

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 whose attributes are to be modified.
[DEFAULT] {CHARACTER SET | CHARSET} charset_name The character set to be modified. The DEFAULT keyword is optional and does not affect the semantics.
[DEFAULT] COLLATE collation_name The collation. 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 test2 and specify the character set as UTF8.

    obclient> CREATE DATABASE test2 DEFAULT CHARACTER SET UTF8;
    Query OK, 1 row affected
    
  • Create a database named test3 that supports read and write operations.

    obclient> CREATE DATABASE test3 READ WRITE;
    Query OK, 1 row affected
    

Contact Us