Purpose
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).
Note
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 OceanBase Database privileges, see Privilege types in MySQL mode.
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}
| [DEFAULT] TABLEGROUP {table_group_name | NULL}
Parameters
| Parameter | Description |
|---|---|
| IF NOT EXISTS | Indicates whether to create the database if it already exists. If the database exists and you do not specify IF NOT EXISTS, an error will be returned. |
| database_name | Specifies the name of the database to be created. |
| [DEFAULT] {CHARACTER SET | CHARSET} charset_name | Specifies the character set (charset) of the database. |
| [DEFAULT] COLLATE collate_name | Specifies the collation of the database. |
| {READ ONLY | READ WRITE} | Specifies the read/write attribute of the database.
|
| [DEFAULT] TABLEGROUP {table_group_name | NULL} | Specifies the default table group (tablegroup) of the database. You can set it to a specified table group name or remove the default table group. |
Examples
Create a database named
test1with the character setUTF-8.obclient> CREATE DATABASE IF NOT EXISTS test1 DEFAULT CHARACTER SET utf8;Create a database named
test2with read/write attributes.obclient> CREATE DATABASE test2 READ WRITE;
References
For information about granting privileges to a user, see Grant privileges.
For information about verifying whether the database is created, see View a database.
For information about modifying the created database, see Modify a database.
For information about deleting the created database, see Delete a database.
