Updated on 2025-10-21 GMT+08:00

Creating a Database Account

Function

This API is used to create a database account for a specified DB instance.

Constraints

  • This operation cannot be performed when the DB instance is in any of the following statuses: creating, changing instance class, changing port, or abnormal.
  • If you want to call this API repeatedly to create database accounts for your DB instance, call it in serial.

URI

  • URI format

    POST /v3/{project_id}/instances/{instance_id}/db_user

  • Parameter description
    Table 1 Parameters

    Parameter

    Mandatory

    Description

    project_id

    Yes

    Project ID of a tenant in a region.

    To obtain the value, see Obtaining a Project ID.

    instance_id

    Yes

    Specifies the DB instance ID.

Request

Table 2 Parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Specifies the username of the database account.

The username consists of 1 to 32 characters. Only lowercase letters, digits, hyphens (-), and underscores (_) are allowed.
  • If the database version is MySQL 5.6, the username consists of 1 to 16 characters.
  • If the database version is MySQL 5.7 or 8.0, the username consists of 1 to 32 characters.

password

Yes

String

Specifies the password of the database account.

Valid value:

The value must be 8 to 32 characters long and contain at least three types of the following characters: uppercase letters, lowercase letters, digits, and special characters (~!@#$%^*-_=+?,()&). The value must be different from the account name or account name spelled backwards.

You are advised to enter a strong password to improve security, preventing security risks such as brute force cracking.

comment

No

String

Specifies remarks of the database account.

The parameter must be 1 to 512 characters long and is supported only for MySQL 8.0.25 and later versions.

is_privilege

No

Boolean

Whether a privileged user is created.

  • true: A privileged user is created.
  • false: A non-privileged user is created.

hosts

No

Array of strings

IP addresses that are allowed to access your DB instance.
  • If the IP address is set to %, all IP addresses are allowed to access your instance.
  • If the IP address is set to 10.10.10.%, all IP addresses in the subnet 10.10.10.X are allowed to access your instance.
  • Multiple IP addresses can be added.

databases

No

Array of objects

Databases that you can log in using the account. For details, see Table 3.

Table 3 databases element structure description

Parameter

Mandatory

Type

Description

name

Yes

String

Database name.

readonly

No

Boolean

Whether the database is read-only.

  • true: indicates the database is read-only.
  • false: indicates the database is readable and writable.

Example Request

Creating a database account named rds

{
    "name": "rds",
    "password": "************",
    "comment": "mysql",
     is_privilege: false,
    "hosts": [
        "%"  
    ],
    "databases" : [
       {
           "name" : "***",
            "readonly" : false
       }
    ]
}

Response

  • Normal response
    Table 4 Parameters

    Parameter

    Type

    Description

    resp

    String

    Returns successful if the invoking is successful.

Status Code

Error Code

For details, see Error Codes.