All Products
Search
Document Center

AnalyticDB:CLI integration example

Last Updated:Aug 12, 2025

The Alibaba Cloud Command Line Interface (CLI) is a universal command-line tool based on OpenAPI. You can use the CLI to automate the management and maintenance of AnalyticDB for MySQL. This topic describes how to use the CLI to call AnalyticDB for MySQL operations and provides an example.

Prerequisites

If you are not familiar with the Alibaba Cloud CLI, see What is Alibaba Cloud CLI?.

Install the Alibaba Cloud CLI

Before you can use the Alibaba Cloud CLI, you must install it. The Alibaba Cloud CLI can be installed on Windows, Linux, and macOS. Follow the installation instructions for your operating system.

You can also use Cloud Shell to test Alibaba Cloud CLI commands. For more information, see What is Cloud Shell?.

Configure the Alibaba Cloud CLI

Important

Using an Alibaba Cloud account to call APIs poses a high security risk because the account has full access permissions. For improved security, create and use a Resource Access Management (RAM) user for API calls and daily operations and maintenance (O&M).

Before you can use the Alibaba Cloud CLI, you must configure your identity credentials and a region ID. The Alibaba Cloud CLI supports multiple types of identity credentials. For more information, see Credential types. This topic uses AccessKey credentials as an example. The procedure is as follows:

  1. Create a RAM user and grant the required permissions. For more information, see Create a RAM user and Grant permissions to a RAM user.

    Important

    This example requires you to grant the AliyunADBFullAccess access policy to the RAM user. In practice, grant permissions as needed before you make API calls.

  2. After you create the RAM user and grant permissions, create an AccessKey pair for the user. Record the AccessKey ID and AccessKey secret for later use in configuring credentials. For more information, see Create an AccessKey.

  3. Obtain and record the ID of an available region. The Alibaba Cloud CLI sends API requests to the region that you specify. For available regions for Data Lakehouse, Basic, and Enterprise editions, see Endpoints.

    Note

    You can use the --region option to specify a region for a single command. This option overrides the region specified in the default credential configuration and environment variables. For more information, see Command-line options.

  4. Use the AccessKey pair of the RAM user to configure the AccessKey credentials. Name the configuration profile AkProfile. For more information, see Configuration examples.

Generate a CLI command example

  1. Go to the Data Lakehouse, Basic, and Enterprise editions API Debugging page.

  2. In the search box on the left, search for the API you want to use. On the Parameters tab, enter the parameters as described in the API documentation. Click the CLI Example tab to the right of the Parameters tab to generate a command example with the parameters that you entered.image

    • Click the image button to open Cloud Shell and quickly test the command.

    • Click the image button to copy the CLI example to the clipboard. You can then paste it into your local shell tool to run the command.

      • When you copy the example to your local shell for testing, note the parameter format. For more information about the parameter formats for the Alibaba Cloud CLI, see Parameter formats.

      • The OpenAPI Explorer automatically adds the --region option to the generated example. When you run the command locally, the Alibaba Cloud CLI overrides the default region and uses the specified region. You can remove or keep this option as required.

Call an API

Command structure

The general command structure for the Alibaba Cloud CLI is as follows. For more information, see Generate and call a command.

aliyun <command> <subcommand> [options and parameters]

Common command options

You can use command options to modify the default behavior of a command or provide additional features. Common options include the following:

  • --profile <profileName>: Use the --profile option to specify a configuration profile. Replace profileName with a valid profile name. This option overrides the default credential configuration and environment variables.

  • --help: To obtain help information for a command, add the --help option at any command level. For more information, see Get help information.

For more information, see Command-line options.

Example

This example shows how to use the Alibaba Cloud CLI to call the DescribeDBClusterAttribute operation in AnalyticDB for MySQL. This operation queries information about a specific Data Lakehouse, Basic, or Enterprise edition cluster. For more information about the DescribeDBClusterAttribute operation, see DescribeDBClusterAttribute.

  1. Run the command.

    aliyun adb DescribeDBClusterAttribute --region cn-hangzhou --DBClusterId 'amv-bp15yg4o68****' --version 2021-12-01 --method POST --force
  2. Output

    {
            "Items": {
                    "DBCluster": [
                            {
                                    "ClickhouseEngineCacheSize": -1,
                                    "ClickhouseEngineEnabled": false,
                                    "CommodityCode": "ads",
                                    "ComputeResource": "0ACU",
                                    "ComputeResourceTotal": "0ACU",
                                    "ConnectionString": "amv-bp15yg4o68****.ads.aliyuncs.com",
                                    "CreationTime": "2024-09-26T05:25:46Z",
                                    "DBClusterDescription": "amv-bp15yg4o68****",
                                    "DBClusterId": "amv-bp15yg4o68****",
                                    "DBClusterNetworkType": "VPC",
                                    "DBClusterStatus": "Running",
                                    "DBClusterType": "Common",
                                    "DBVersion": "5.0",
                                    "Engine": "3.2.X.X",
                                    "EngineVersion": "3.2.2.2",
                                    "ExpireTime": "",
                                    "KmsId": "",
                                    "LockMode": "Unlock",
                                    "LockReason": "",
                                    "MaintainTime": "15:00Z-16:00Z",
                                    "Mode": "flexible",
                                    "PayType": "Postpaid",
                                    "Port": "3306",
                                    "ProductForm": "IntegrationForm",
                                    "ProductVersion": "EnterpriseVersion",
                                    "RegionId": "cn-hangzhou",
                                    "ReservedACU": "0ACU",
                                    "ReservedNodeCount": 3,
                                    "ReservedNodeSize": "8ACU",
                                    "ResourceGroupId": "rg-acfmz7u4zzrngoa",
                                    "StorageResource": "24ACU",
                                    "StorageResourceTotal": "24ACU",
                                    "SupportedFeatures": {
                                            "AutoMC": true,
                                            "ClickhouseEngine": true
                                    },
                                    "UserENIStatus": false,
                                    "VPCId": "vpc-bp15lqdl91m0fdc****",
                                    "VSwitchId": "vsw-bp1k9jdi0yznq****",
                                    "ZoneId": "cn-hangzhou-k"
                            }
                    ]
            },
            "RequestId": "C42A167C-620C-5CF4-B016-663E3****"
    }