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).
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
| Parameter | Description |
|---|---|
| IF NOT EXISTS | Indicates 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_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 | Sets the collation of the database. |
| {READ ONLY | READ WRITE} | Specifies the read/write attribute of the database.
|
Examples
-
Create a database named
test1with the character setUTF-8.CREATE DATABASE IF NOT EXISTS test1 DEFAULT CHARACTER SET utf8; -
Create a database named
test2with 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.