Skip to main content
Version: V1.1.0

createDatabase - Create a database

The createDatabase() method is used to create a new database.

info
  • This API can only be used when connected with SeekdbAdminClient. For more information about SeekdbAdminClient, see SeekdbAdminClient.

  • Currently, when you use createDatabase, you cannot specify the properties of the database. The database will be created with default values for all properties. If you want to create a database with specific properties, you can try creating it using SQL. For more information, see Create a database.

Prerequisites

  • You have installed seekdb-js. For more information, see Quick start.

  • You have installed the server mode of seekdb. For more information, see Deploy seekdb by using yum install.

  • You are connected to the database. For more information, see SeekdbAdminClient.

  • The user to which you are connected has the CREATE privilege. For more information about how to view the privileges of the current user, see View user privileges. If the user does not have this privilege, contact the administrator to grant it. For more information about how to directly grant privileges, see Directly grant privileges.

Limitations

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

  • The maximum length of a database name is 128 characters.

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

  • Avoid using reserved keywords as database names.

    For more information about reserved keywords, see Reserved keywords.

Considerations

  • We recommend that you give the database a meaningful name that reflects its purpose and content. For example, you can use app_id_subapp_name_db as the database name.

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

  • You can create a database with a name that consists solely of digits by enclosing the name in backticks (`). However, this is not recommended because such names lack clear meaning and require backticks when queried, which can lead to unnecessary complexity and confusion.

Request parameters

createDatabase(name: string, tenant?: string)
ParameterTypeRequiredDescriptionExample value
namestringYesThe name of the database to be created.my_database
tenantstringNo
  • When the server mode of seekdb is used, this parameter is not required.
  • When OceanBase Database is used, this parameter is required.
The tenant to which the created database belongs.test_tenant

Request example

import { SeekdbAdminClient } from "seekdb";

// Remote server mode - Database management (seekdb Server)
const admin = new SeekdbAdminClient({
host: "127.0.0.1",
port: 2881,
user: "root",
password: ""
});

await admin.createDatabase("my_database");

Response parameters

None