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.
Note
CREATE DATABASE is equivalent to CREATE SCHEMA.
Required privileges
To execute the CREATE DATABASE statement, you must have the global CREATE privilege. For more information about privileges in OceanBase Database, 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 | Specifies not to create the database if the database already exists. If the database already exists and IF NOT EXISTS is not specified, an error is reported. |
| database_name | The name of the database to be created. |
| [DEFAULT] {CHARACTER SET | CHARSET} charset_name | The character set of the database. |
| [DEFAULT] COLLATE collate_name | The collation of the database. |
| {READ ONLY | READ WRITE} | The read/write property of the database.
|
| [DEFAULT] TABLEGROUP {table_group_name | NULL} | The default table group of the database. You can specify a table group or cancel 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
test2that supports read and write operations.obclient> CREATE DATABASE test2 READ WRITE;
References
For more information about how to grant user privileges, see Grant direct privileges.
For more information about how to verify whether a database is created, see View databases.
For more information about how to modify a created database, see Modify a database.
For more information about how to drop a created database, see Drop a database.