Skip to main content

Create a database

This topic describes how to create a database by using SQL statements. It also provides the prerequisites, database overview, limitations, and recommendations for creating a database, and gives some examples.

Database overview

In seekdb, a database contains tables, indexes, and metadata of database objects. We recommend that you do not use the default database, such as the test database, in a production environment.

Prerequisites

Before you create a database, make sure that the following conditions are met:

  • You have deployed seekdb. For more information about how to deploy seekdb, see Overview.

  • You have connected to seekdb.

  • You have the CREATE privilege. For more information about how to view the privileges of the current user, see View user privileges. If you do not have this privilege, contact the administrator to grant it to you. For more information about how to directly grant privileges to a user, see Directly grant privileges.

Limitations

  • In seekdb, the name of each database must be globally unique.

  • The length of a database name cannot exceed 128 characters.

  • A database name can contain only uppercase and lowercase letters, digits, underscores, dollar signs, and Chinese characters.

  • You cannot use reserved keywords as database names.

    For more information about the reserved keywords of seekdb, see Reserved keywords.

Recommendations

  • We recommend that you name the database in a meaningful way to reflect its purpose and content. For example, you can name the database Application Identifier_Subapplication Name (Optional)_db.

  • We recommend that you create the database and related users by using the root user and grant only the necessary privileges to ensure the security and controllability of the database.

  • When you create a database, set appropriate default character sets and collations to ensure the correct storage and sorting of data. To accommodate the long-term development of your business, we recommend that you use the utf8mb4 character set to store most characters.

  • You can create a database with a name that consists only of digits by enclosing the name in backticks (). However, this is not recommended because such names are not meaningful and require backticks () when they are queried, which can cause unnecessary complexity and confusion.

    For more information about the character set encoding supported by the database, see Database-level character set.

Use the CLI to create a database

Run the CREATE DATABASE statement to create a database.

The syntax of the CREATE DATABASE statement is as follows:

CREATE DATABASE [IF NOT EXISTS] database_name [database_option_list];

Parameters:

  • database_name: the name of the database.
  • database_option_list: the list of options for setting the characteristics, behaviors, and attributes of the database, such as the character set and collation.
info

You can run the SHOW DATABASES; statement to view the databases.

Examples

Example 1: Create a database and specify the character set

Create a database named test_db and specify the character set as utf8mb4.

CREATE DATABASE test_db DEFAULT CHARACTER SET utf8mb4;

Example 2: Create a read-only database

Create a read-only database named test_ro_db.

CREATE DATABASE test_ro_db READ ONLY;

Example 3: Create a read/write database

Create a read/write database named test_rw_db.

CREATE DATABASE test_rw_db READ WRITE;

What to do next

After you create a database, you can perform the following common operations:

  • Create the required tables in the database and define the structure and fields of the tables. For more information about how to create tables, see Create a table.