create_database - Create a database
The create_database() function is used to create a new database.
-
This interface can only be used when you are connected to the database using
AdminClient. For more information aboutAdminClient, see Admin Client. -
Currently, when you use
create_databaseto create a database, you cannot specify the database properties. The database will be created based on the default values of the properties. If you want to create a database with specific properties, you can try to create it using SQL. For more information about how to create a database using SQL, see Create a database.
Prerequisites
-
You have installed pyseekdb. For more information about how to install pyseekdb, see Get Started.
-
You are connected to the database. For more information about how to connect to the database, see Admin Client.
-
If you are using server mode of seekdb or OceanBase Database, make sure that the connected user has the
CREATEprivilege. For more information about how to check 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 a seekdb instance or OceanBase Database, 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.
Recommendations
-
We recommend that you give the database a meaningful name that reflects its purpose and content. For example, you can use
Application Identifier_Sub-application name (optional)_dbas the database name. -
We recommend that you create the database and related users using the root user and assign only the necessary privileges to ensure the security and controllability of the database.
-
You can create a database with a name consisting only of digits by enclosing the name in backticks (
), but this is not recommended. This is because names consisting only of digits have no clear meaning, and queries require the use of backticks (), which can lead to unnecessary complexity and confusion.
Request parameters
create_database(name, tenant=DEFAULT_TENANT)
| Parameter | Type | Required | Description | Example value |
|---|---|---|---|---|
name | string | Yes | The name of the database to be created. | my_database |
tenant | string | No
| The tenant to which the database belongs. | test_tenant |
Request example
import pyseekdb
# Embedded mode
admin = pyseekdb.AdminClient(path="./seekdb")
# Create database
admin.create_database("my_database")
Response parameters
None