Description
This statement is used to create a database and can specify the database's default attributes (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 AI Database privileges, see Permission classification.
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 | It indicates that if the database already exists, it will not be created. When creating a database, if the database exists and this option is not specified, IF NOT EXISTS, an error will be reported. |
| database_name | Specifies the name of the database to be created. |
| [DEFAULT] {CHARACTER SET \ | CHARSET} charset_name | Sets the character set (charset) of the database. |
| [DEFAULT] COLLATE collate_name | Set the database collation. |
| {READ ONLY \ | READ WRITE} | Specifies the read and write properties of the database.
|
| [DEFAULT] TABLEGROUP {table_group_name \ | NULL} | Specifies the default table group for a database. You can set it to a specified table group name or disable the default table group for the database. |
Examples
Create a database named
test1and set its character set toUTF-8.obclient> CREATE DATABASE IF NOT EXISTS test1 DEFAULT CHARACTER SET utf8;Create a database named
test2with read and write attributes.obclient> CREATE DATABASE test2 READ WRITE;
References
For more information about how to grant user privileges, see Grant privileges directly.
For more information about how to check whether the database has been created, see View databases.
To modify the created database, see Modify a database.
To delete a created database, see Drop a database.