Skip to main content
Version: V1.4.0

CREATE DATABASE

Description​

This statement is used to create a database and can specify the default properties of the database (such as the default character set and collation).

info

CREATE DATABASE is equivalent to CREATE SCHEMA.

Privilege requirements​

To execute the CREATE DATABASE statement, the current user must have the global CREATE privilege. For more information about seekdb privileges, see seekdb privilege types.

Syntax​

CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] database_name [database_option...]

database_option:
[DEFAULT] {CHARACTER SET | CHARSET} charset_name
| [DEFAULT] COLLATE collate_name
| {READ ONLY | READ WRITE}

Parameters​

ParameterDescription
IF NOT EXISTSIndicates that if the database already exists, it should not be created. When creating a database, if the database already exists and the IF NOT EXISTS clause is not specified, an error will be returned.
database_nameSpecifies the name of the database to be created.
[DEFAULT] {CHARACTER SET | CHARSET} charset_nameSets the character set (charset) of the database.
[DEFAULT] COLLATE collate_nameSets the collation of the database.
{READ ONLY | READ WRITE}Specifies the read/write attribute of the database.
  • READ ONLY: Sets the database to read-only mode, prohibiting write operations.
  • READ WRITE: Sets the database to read/write mode, allowing read and write operations.

Examples​

  • Create a database named test1 with the utf8mb4 character set.

    CREATE DATABASE IF NOT EXISTS test1 DEFAULT CHARACTER SET utf8mb4;
  • Create a database named test2 with read/write attributes.

    CREATE DATABASE test2 READ WRITE;

References​

  • For information about granting privileges to a user, see Grant privileges.

  • For information about verifying whether the database was created successfully, see View databases.

  • For information about modifying a created database, see Modify a database.

  • For information about deleting a created database, see Delete a database.