Creates a database for a PolarDB cluster.

Before you call this operation, make sure that the following requirements are met:

  • The cluster is in the Running state.
  • The cluster is unlocked.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String No CreateDatabase

The operation that you want to perform. Set the value to CreateDatabase.

DBClusterId String Yes pc-**************

The ID of the PolarDB cluster.

DBName String Yes testDB

The name of the database. The name must meet the following requirements:

  • The name can contain lowercase letters, digits, hyphens (-), and underscores (_).
  • The name must start with a lowercase letter and end with a lowercase letter or a digit. The name must be 1 to 64 characters in length.
Note The name cannot be test, mysql, or another keyword that is reserved by the system.
CharacterSetName String Yes utf8

The character set that is used by the database. For more information, see Character sets.

DBDescription String No testdesc

The description of the database. The description must meet the following requirements:

  • It cannot start with http:// or https://.
  • It must be 2 to 256 characters in length.
Note If the database engine of the PolarDB cluster is PolarDB O Edition or the ApsaraDB PolarDB PostgreSQL-compatible edition, this parameter is required. If the database engine of the PolarDB cluster is the ApsaraDB PolarDB MySQL-compatible edition, this parameter is optional.
AccountName String No testacc

The name of the account that is authorized to access the database. You can call the DescribeAccounts operation to query account information.

Note
  • You can specify only a standard account. By default, privileged accounts have all permissions on all databases. You do not need to authorize the privileged accounts to access the database.
  • If the database engine of the PolarDB cluster is PolarDB O Edition or the ApsaraDB PolarDB PostgreSQL-compatible edition, this parameter is required. If the database engine of the PolarDB cluster is the ApsaraDB PolarDB MySQL-compatible edition, this parameter is optional.
AccountPrivilege String No ReadWrite

The permissions of the account. Valid values:

  • ReadWrite: The account has the read and write permissions on the database.
  • ReadOnly: The account has the read-only permissions on the database.
  • DMLOnly: The account has the permissions only to execute DML statements on the database.
  • DDLOnly: The account has the permissions only to execute DDL statements on the database.

If you leave this parameter empty, the default value ReadWrite is used.

Note
  • This parameter is valid only when the AccountName parameter is specified.
  • If the database engine of the PolarDB cluster is PolarDB O Edition or the ApsaraDB PolarDB PostgreSQL-compatible edition, this parameter is required. If the database engine of the PolarDB cluster is the ApsaraDB PolarDB MySQL-compatible edition, this parameter is optional.
Collate String No C

The language that specifies the collation of the database that is to be created.

Note
  • The language must be compatible with the character set that is specified by the CharacterSetName parameter.
  • If the database engine of the PolarDB cluster is PolarDB O Edition or the ApsaraDB PolarDB PostgreSQL-compatible edition, this parameter is required. If the database engine of the PolarDB cluster is the ApsaraDB PolarDB MySQL-compatible edition, this parameter is optional.
Ctype String No C

The language that specifies the character type of the database.

Note
  • The language must be compatible with the character set that is specified by the CharacterSetName parameter.
  • The specified value must be the same as that of the Collate parameter.
  • If the database engine of the PolarDB cluster is PolarDB O Edition or the ApsaraDB PolarDB PostgreSQL-compatible edition, this parameter is required. If the database engine of the PolarDB cluster is the ApsaraDB PolarDB MySQL-compatible edition, this parameter is optional.

Response parameters

Parameter Type Example Description
RequestId String 93E98F25-BE02-40DA-83E3-F77F8D******

The ID of the request.

Examples

Sample requests

http(s)://polardb.aliyuncs.com/?Action=CreateDatabase
&CharacterSetName=utf8
&DBClusterId=pc-**************
&DBName=testDB
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<CreateDatabaseResponse>  
     <RequestId>93E98F25-BE02-40DA-83E3-F77F8D******</RequestId>
</CreateDatabaseResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "93E98F25-BE02-40DA-83E3-F77F8D******"
}

Error codes

HTTP status code Error code Error message Description
400 InvalidDBName.Malformed The specified parameter DBName is not valid. The error message returned because the specified value of the DBName parameter is invalid.

For a list of error codes, visit the API Error Center.