This topic describes how to create a database with some examples.
Overview
In the MySQL mode of OceanBase Database, a database is a collection of database objects. After you connect to a MySQL tenant of OceanBase Database, you can create a database in the MySQL tenant to store and manage its data.
Prerequisites
You have the CREATE privilege. For more information about how to view your privileges, see View user privileges. If you do not have the required privileges, contact the administrator. For more information about how to grant privileges, see Modify user privileges.
Considerations
Do not directly use the default database in the system. We recommend that you use SQL statements to create your own database.
In OceanBase Database, the name of each database must be globally unique.
Do not use reserved keywords as the database name. For more information about the reserved keywords in OceanBase Database's MySQL mode, see Reserved keywords.
The database name can be up to 128 bytes in length. We recommend that you specify the database name in the format of application ID (4 digits) + sub-application name (up to 4 digits, optional) + db, such as
gcdsdborgcdsamndb.To adapt to long-term business development, the character set of the database must be able to store most characters. We recommend that you use the
utf8mb4character set when you create a database. For more information about the character sets supported by OceanBase Database, see Database-level character sets.
Statement for creating databases
You can use the CREATE DATABASE statement to create a database. Then, complete the creation of the database based on the suggestions and examples provided in this topic.
Examples
Create a database and specify its character set
Execute the following statement to create a database named testdb and specify the character set as utf8mb4:
obclient [(none)]> CREATE DATABASE testdb DEFAULT CHARACTER SET utf8mb4;
Create a read-only database
Execute the following statement to create a read-only database named testrodb:
obclient [(none)]> CREATE DATABASE testrdb READ ONLY;
Create a database that supports read and write operations
Execute the following statement to create a database named testrwdb that supports read and write operations:
obclient [(none)]> CREATE DATABASE testrwdb READ WRITE;