更新时间:2024-12-16 GMT+08:00
分享

创建数据库实例

功能介绍

创建云数据库TaurusDB实例。

调用方法

请参见如何调用API

URI

POST /v3/{project_id}/instances

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

租户在某一Region下的project ID。

获取方法请参见获取项目ID

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。

通过调用IAM服务获取用户Token接口获取。

请求响应成功后在响应消息头中包含的“X-Subject-Token”的值即为Token值。

X-Language

String

请求语言类型。默认en-us。

取值范围:

  • en-us

  • zh-cn

表3 请求Body参数

参数

是否必选

参数类型

描述

region

String

区域ID。

name

String

实例名称。用于表示实例的名称,同一租户下,同类型的实例名可重名。

取值范围:最小为4个字符,最大为64个字符且不超过64个字节(注意:一个中文字符占用3个字节),必须以字母或中文开头,区分大小写,可以包含字母、数字、中划线、下划线或中文,不能包含其他特殊字符。

datastore

MysqlDatastoreInReq object

数据库信息。

mode

String

实例类型,目前仅支持Cluster。

flavor_ref

String

规格码。使用可参考查询数据库规格响应消息表5中的“spec_code”。

vpc_id

String

虚拟私有云ID,获取方法如下:

  • 方法1:登录虚拟私有云服务的控制台界面,在虚拟私有云的详情页面查找VPC ID。

  • 方法2:通过虚拟私有云服务的API接口查询,具体操作可参考查询VPC列表

subnet_id

String

子网的网络ID,获取方法如下:

  • 方法1:登录虚拟私有云服务的控制台界面,单击VPC下的子网,进入子网详情页面,查找网络ID。

  • 方法2:通过虚拟私有云服务的API接口查询,具体操作可参考查询子网列表

password

String

数据库密码。

取值范围:至少包含以下字符的三种:大小写字母、数字和特殊符号|.~!@#$%^*-_=+?,()&,长度8~32个字符。

建议您输入高强度密码,以提高安全性,防止出现密码被暴力破解等安全风险。如果您输入弱密码,系统会自动判定密码非法。

availability_zone_mode

String

可用区类型。

取值范围:

  • single:单可用区。

  • multi:多可用区。

slave_count

Integer

只读节点个数。单次接口调用最多支持创建9个只读节点。

charge_info

MysqlChargeInfo object

计费类型信息,支持包年包月和按需,默认为按需。

说明:DeC专属云账号不支持创建包年/包月实例。

security_group_id

String

安全组ID。如果实例所选用的子网开启网络ACL进行访问控制,则该参数非必选。如果未开启ACL进行访问控制,则该参数必选。获取方法如下:

  • 方法1:登录虚拟私有云服务的控制台界面,在安全组的详情页面查找安全组ID。

  • 方法2:通过虚拟私有云服务的API接口查询,具体操作可参考查询安全组列表

configuration_id

String

参数模板ID。使用可参考查询参数模板中响应消息表5的“id”。

backup_strategy

MysqlBackupStrategy object

自动备份策略。

time_zone

String

时区。默认时区为UTC。

master_availability_zone

String

主可用区ID,创建单可用区实例选填,多可用区实例必填,请参考地区和终端节点

volume

MysqlVolume object

volume信息。创建包年/包月实例可选。创建按需实例时不可选。

tags

Array of MysqlTags objects

标签列表,根据标签键值对创建实例。

  • {key}表示标签键,不可以为空或重复。

  • {value}表示标签值,可以为空。

如果创建实例时同时使用多个标签键值对,中间使用逗号分隔开,最多包含10组。

lower_case_table_names

Integer

表名大小写是否敏感,默认值是1。

取值范围:

  • 0:表名被存储成固定且表名称大小写敏感。

  • 1:表名将被存储成小写且表名称大小写不敏感。

enterprise_project_id

String

企业项目ID。如果账户开通企业项目服务则该参数必选,未开启该参数不可选。

dedicated_resource_id

String

专属资源池ID,只有开通专属资源池后才支持此参数。

restore_point

MysqlRestorePoint object

备份恢复信息。

tde_info

MysqlTdeInfo object

透明数据加密配置信息,支持AES256、SM4加密算法。

透明加密功能目前处于公测阶段,如需使用,请提交工单联系客服人员申请权限。

表4 MysqlDatastoreInReq

参数

是否必选

参数类型

描述

type

String

数据库引擎,现在只支持gaussdb-mysql。

version

String

数据库版本。

两位数的大版本号,获取方法请参见查询数据库引擎的版本返回的name字段。

kernel_version

String

内核数据库版本。如果需要指定具体的内核版本,请联系客服人员添加白名单。

完整的四位内核数据库版本,获取方法请参见查询数据库引擎的版本返回的kernel_version字段。

表5 MysqlChargeInfo

参数

是否必选

参数类型

描述

charge_mode

String

计费模式。

取值范围:

  • prePaid:预付费,即包年/包月。

  • postPaid:后付费,即按需付费。

period_type

String

订购周期类型。

取值范围:

  • month:包月。

  • year:包年。

说明:“charge_mode”为“prePaid”时生效,且为必选值。

period_num

Integer

“charge_mode”为“prePaid”时生效,且为必选值,指定订购的时间。

取值范围:

  • “period_type”为“month”时,取值为1~9。

  • “period_type”为“year”时,取值为1~3。

is_auto_renew

String

创建包年/包月实例时可指定,表示是否自动续订,续订的周期和原周期相同,且续订时会自动支付。

  • true:为自动续订。

  • false:为不自动续订,默认该方式。

is_auto_pay

String

创建包年/包月实例时可指定,表示是否自动从客户的账户中支付,此字段不影响自动续订的支付方式。

  • true:为自动支付,默认该方式。

  • false:为手动支付。

表6 MysqlBackupStrategy

参数

是否必选

参数类型

描述

start_time

String

自动备份开始时间段。自动备份将在该时间一个小时内触发。

取值范围:非空,格式必须为hh:mm-HH:MM且有效,当前时间指UTC时间。

  1. HH取值必须比hh大1。

  2. mm和MM取值必须相同,且取值必须为00。

keep_days

String

自动备份保留天数,取值范围:1-732。

表7 MysqlVolume

参数

是否必选

参数类型

描述

size

String

磁盘大小。默认值为10,单位GB。

取值范围:10~128000,必须为10的整数倍。

表8 MysqlTags

参数

是否必选

参数类型

描述

key

String

标签键。最大长度36个unicode字符。key不能为空或者空字符串,不能为空格。

字符集:A-Z,a-z ,0-9,‘-’,‘_’,UNICODE字符(\u4E00-\u9FFF)。

value

String

标签值。最大长度43个unicode字符。可以为空字符串。

字符集:A-Z,a-z ,0-9,‘.’,‘-’,‘_’,UNICODE字符(\u4E00-\u9FFF)。

表9 MysqlRestorePoint

参数

是否必选

参数类型

描述

source_instance_id

String

源实例ID。

restore_time

Long

需要恢复的时间点。(Point-In-Time Recovery, PITR)。

backup_id

String

备份文件ID。

type

String

备份类型。当参数为空时,backup_id不能为空,即默认按备份文件恢复。

当参数不为空时,取值范围:

  • backup:表示按备份文件恢复。

  • timestamp:表示按时间点恢复。

表10 MysqlTdeInfo

参数

是否必选

参数类型

描述

enable_tde

Boolean

是否打开透明加密功能。

encryption_type

String

透明加密算法,支持AES256、SM4加密算法。

响应参数

状态码: 201

表11 响应Body参数

参数

参数类型

描述

instance

MysqlInstanceResponse object

实例信息

job_id

String

实例创建的任务ID。

仅创建按需实例时会返回该参数。

order_id

String

订单号,创建包年包月时返回该参数。

表12 MysqlInstanceResponse

参数

参数类型

描述

id

String

实例ID,严格匹配UUID规则。

name

String

实例名称。用于表示实例的名称。

status

String

实例状态。

datastore

MysqlDatastoreInRes object

数据库信息。

mode

String

实例类型,仅支持Cluster。

configuration_id

String

参数组ID。

port

String

数据库端口信息。

backup_strategy

MysqlBackupStrategy object

自动备份策略。

enterprise_project_id

String

企业项目ID。

region

String

区域ID,与请求参数相同。

availability_zone_mode

String

可用区模式,与请求参数相同。

master_availability_zone

String

主可用区ID。

vpc_id

String

虚拟私有云ID,与请求参数相同。

security_group_id

String

安全组ID,与请求参数相同。

subnet_id

String

子网ID,与请求参数相同。

flavor_ref

String

规格码,与请求参数相同。

charge_info

MysqlChargeInfo object

计费类型信息,支持包年包月和按需,默认为按需。

volume

MysqlVolumeResp object

volume信息。创建包年/包月实例有返回。

表13 MysqlDatastoreInRes

参数

参数类型

描述

type

String

数据库引擎,现在只支持gaussdb-mysql。

version

String

数据库版本。

kernel_version

String

内核数据库版本。

表14 MysqlBackupStrategy

参数

参数类型

描述

start_time

String

自动备份开始时间段。自动备份将在该时间一个小时内触发。

取值范围:非空,格式必须为hh:mm-HH:MM且有效,当前时间指UTC时间。

  1. HH取值必须比hh大1。

  2. mm和MM取值必须相同,且取值必须为00。

keep_days

String

自动备份保留天数,取值范围:1-732。

表15 MysqlChargeInfo

参数

参数类型

描述

charge_mode

String

计费模式。

取值范围:

  • prePaid:预付费,即包年/包月。

  • postPaid:后付费,即按需付费。

period_type

String

订购周期类型。

取值范围:

  • month:包月。

  • year:包年。

说明:“charge_mode”为“prePaid”时生效,且为必选值。

period_num

Integer

“charge_mode”为“prePaid”时生效,且为必选值,指定订购的时间。

取值范围:

  • “period_type”为“month”时,取值为1~9。

  • “period_type”为“year”时,取值为1~3。

is_auto_renew

String

创建包年/包月实例时可指定,表示是否自动续订,续订的周期和原周期相同,且续订时会自动支付。

  • true:为自动续订。

  • false:为不自动续订,默认该方式。

is_auto_pay

String

创建包年/包月实例时可指定,表示是否自动从客户的账户中支付,此字段不影响自动续订的支付方式。

  • true:为自动支付,默认该方式。

  • false:为手动支付。

表16 MysqlVolumeResp

参数

参数类型

描述

size

Integer

磁盘大小。单位GB。

取值范围:10~128000,为10的整数倍。

状态码: 400

表17 响应Body参数

参数

参数类型

描述

error_code

String

错误码。

error_msg

String

错误消息。

状态码: 500

表18 响应Body参数

参数

参数类型

描述

error_code

String

错误码。

error_msg

String

错误消息。

请求示例

  • 创建计费模式为按需计费,自动备份开始时间是08:00-09:00的实例。

    POST https://{endpoint}/v3/054e292c9880d4992f02c0196d3ea468/instances
    
    {
      "name" : "gaussdb-mysql-instance1",
      "region" : "br-iaas-odin1",
      "charge_info" : {
        "charge_mode" : "postPaid"
      },
      "datastore" : {
        "type" : "gaussdb-mysql",
        "version" : "8.0"
      },
      "mode" : "Cluster",
      "flavor_ref" : "gaussdb.mysql.xlarge.arm.4",
      "vpc_id" : "3cedfc54-b105-4652-a4e0-847b11576b58",
      "subnet_id" : "c1cfa53c-65d3-431e-8552-326bf310c7ad",
      "security_group_id" : "fc577a1a-f202-424a-977f-24faec3fdd55",
      "configuration_id" : "43570e0de32e40c5a15f831aa5ce4176pr07",
      "password" : "***",
      "backup_strategy" : {
        "start_time" : "08:00-09:00"
      },
      "availability_zone_mode" : "single",
      "slave_count" : 1,
      "enterprise_project_id" : 0
    }
  • 将备份文件恢复到按需计费的新实例。

    POST https://{endpoint}/v3/054e292c9880d4992f02c0196d3ea468/instances
    
    {
      "name" : "gaussdb-mysql-instance2",
      "region" : "br-iaas-odin1",
      "charge_info" : {
        "charge_mode" : "postPaid"
      },
      "datastore" : {
        "type" : "gaussdb-mysql",
        "version" : "8.0"
      },
      "mode" : "Cluster",
      "flavor_ref" : "gaussdb.mysql.xlarge.arm.4",
      "vpc_id" : "3cedfc54-b105-4652-a4e0-847b11576b58",
      "subnet_id" : "c1cfa53c-65d3-431e-8552-326bf310c7ad",
      "security_group_id" : "fc577a1a-f202-424a-977f-24faec3fdd55",
      "configuration_id" : "43570e0de32e40c5a15f831aa5ce4176pr07",
      "password" : "***",
      "backup_strategy" : {
        "start_time" : "08:00-09:00"
      },
      "availability_zone_mode" : "single",
      "slave_count" : 1,
      "enterprise_project_id" : 0,
      "restore_point" : {
        "source_instance_id" : "7033e7c3cf93438797d44ad7ae0a7d95in07",
        "backup_id" : "7ffbf305376b4cbea0ae491257b6aaf9br07",
        "type" : "backup"
      }
    }
  • 按时间点恢复到按需计费的新实例。

    POST https://{endpoint}/v3/054e292c9880d4992f02c0196d3ea468/instances
    
    {
      "name" : "gaussdb-mysql-instance3",
      "region" : "br-iaas-odin1",
      "charge_info" : {
        "charge_mode" : "postPaid"
      },
      "datastore" : {
        "type" : "gaussdb-mysql",
        "version" : "8.0"
      },
      "mode" : "Cluster",
      "flavor_ref" : "gaussdb.mysql.xlarge.arm.4",
      "vpc_id" : "3cedfc54-b105-4652-a4e0-847b11576b58",
      "subnet_id" : "c1cfa53c-65d3-431e-8552-326bf310c7ad",
      "security_group_id" : "fc577a1a-f202-424a-977f-24faec3fdd55",
      "configuration_id" : "43570e0de32e40c5a15f831aa5ce4176pr07",
      "password" : "***",
      "backup_strategy" : {
        "start_time" : "08:00-09:00"
      },
      "availability_zone_mode" : "single",
      "slave_count" : 1,
      "enterprise_project_id" : 0,
      "restore_point" : {
        "source_instance_id" : "7033e7c3cf93438797d44ad7ae0a7d95in07",
        "restore_time" : 1673852043000,
        "type" : "timestamp"
      }
    }
  • 创建周期为一个月的包年/包月实例。

    POST https://{endpoint}/v3/054e292c9880d4992f02c0196d3ea468/instances
    
    {
      "name" : "gaussdb-mysql-instance4",
      "region" : "br-iaas-odin1",
      "charge_info" : {
        "charge_mode" : "prePaid",
        "period_type" : "month",
        "period_num" : 1,
        "is_auto_renew" : false,
        "is_auto_pay" : true
      },
      "volume" : {
        "size" : 10
      },
      "datastore" : {
        "type" : "gaussdb-mysql",
        "version" : "8.0"
      },
      "mode" : "Cluster",
      "flavor_ref" : "gaussdb.mysql.xlarge.arm.4",
      "vpc_id" : "3cedfc54-b105-4652-a4e0-847b11576b58",
      "subnet_id" : "c1cfa53c-65d3-431e-8552-326bf310c7ad",
      "security_group_id" : "fc577a1a-f202-424a-977f-24faec3fdd55",
      "configuration_id" : "43570e0de32e40c5a15f831aa5ce4176pr07",
      "password" : "***",
      "backup_strategy" : {
        "start_time" : "08:00-09:00"
      },
      "availability_zone_mode" : "single",
      "slave_count" : 1,
      "enterprise_project_id" : 0,
      "restore_point" : {
        "source_instance_id" : "7033e7c3cf93438797d44ad7ae0a7d95in07",
        "restore_time" : 1673852043000,
        "type" : "timestamp"
      }
    }

响应示例

状态码: 201

Success.

  • 创建按需实例。

    {
      "instance" : {
        "id" : "5eebbb4c0f9f4a99b42ed1b6334569aain07",
        "name" : "gaussdb-mysql-instance1",
        "status" : "BUILD",
        "region" : "br-iaas-odin1",
        "charge_info" : {
          "charge_mode" : "postPaid"
        },
        "datastore" : {
          "type" : "gaussdb-mysql",
          "version" : "8.0",
          "kernel_version" : "2.0.28.18"
        },
        "mode" : "Cluster",
        "port" : 3306,
        "enterprise_project_id" : 0,
        "flavor_ref" : "gaussdb.mysql.xlarge.arm.4",
        "vpc_id" : "3cedfc54-b105-4652-a4e0-847b11576b58",
        "subnet_id" : "c1cfa53c-65d3-431e-8552-326bf310c7ad",
        "security_group_id" : "fc577a1a-f202-424a-977f-24faec3fdd55",
        "configuration_id" : "43570e0de32e40c5a15f831aa5ce4176pr07",
        "backup_strategy" : {
          "start_time" : "08:00-09:00",
          "keep_days" : 7
        },
        "availability_zone_mode" : "single"
      },
      "job_id" : "dff1d289-4d03-4942-8b9f-463ea07c000d"
    }
  • 创建周期为一个月的包年/包月实例。

    {
      "instance" : {
        "id" : "945419c2208e4a5d828b8dddc00223e1in07",
        "name" : "gaussdb-mysql-instance4",
        "status" : "BUILD",
        "region" : "br-iaas-odin1",
        "charge_info" : {
          "charge_mode" : "prePaid",
          "period_type" : "month",
          "period_num" : 1,
          "is_auto_renew" : false,
          "is_auto_pay" : true
        },
        "volume" : {
          "size" : 10
        },
        "datastore" : {
          "type" : "gaussdb-mysql",
          "version" : "8.0",
          "kernel_version" : "2.0.28.18"
        },
        "mode" : "Cluster",
        "port" : 3306,
        "enterprise_project_id" : 0,
        "flavor_ref" : "gaussdb.mysql.xlarge.arm.4",
        "vpc_id" : "3cedfc54-b105-4652-a4e0-847b11576b58",
        "subnet_id" : "c1cfa53c-65d3-431e-8552-326bf310c7ad",
        "security_group_id" : "fc577a1a-f202-424a-977f-24faec3fdd55",
        "configuration_id" : "43570e0de32e40c5a15f831aa5ce4176pr07",
        "backup_strategy" : {
          "start_time" : "08:00-09:00",
          "keep_days" : 7
        },
        "availability_zone_mode" : "single"
      },
      "order_id" : "CS2308241236EEXVF"
    }

SDK代码示例

SDK代码示例如下。

Java

  • 创建计费模式为按需计费,自动备份开始时间是08:00-09:00的实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.gaussdb.v3.region.GaussDBRegion;
    import com.huaweicloud.sdk.gaussdb.v3.*;
    import com.huaweicloud.sdk.gaussdb.v3.model.*;
    
    
    public class CreateGaussMySqlInstanceSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            GaussDBClient client = GaussDBClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(GaussDBRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateGaussMySqlInstanceRequest request = new CreateGaussMySqlInstanceRequest();
            MysqlInstanceRequest body = new MysqlInstanceRequest();
            MysqlBackupStrategy backupStrategybody = new MysqlBackupStrategy();
            backupStrategybody.withStartTime("08:00-09:00");
            MysqlDatastoreInReq datastorebody = new MysqlDatastoreInReq();
            datastorebody.withType("gaussdb-mysql")
                .withVersion("8.0");
            MysqlChargeInfo chargeInfobody = new MysqlChargeInfo();
            chargeInfobody.withChargeMode(MysqlChargeInfo.ChargeModeEnum.fromValue("postPaid"));
            body.withEnterpriseProjectId("0");
            body.withSlaveCount(1);
            body.withAvailabilityZoneMode("single");
            body.withBackupStrategy(backupStrategybody);
            body.withPassword("***");
            body.withConfigurationId("43570e0de32e40c5a15f831aa5ce4176pr07");
            body.withSecurityGroupId("fc577a1a-f202-424a-977f-24faec3fdd55");
            body.withSubnetId("c1cfa53c-65d3-431e-8552-326bf310c7ad");
            body.withVpcId("3cedfc54-b105-4652-a4e0-847b11576b58");
            body.withFlavorRef("gaussdb.mysql.xlarge.arm.4");
            body.withMode("Cluster");
            body.withDatastore(datastorebody);
            body.withName("gaussdb-mysql-instance1");
            body.withRegion("br-iaas-odin1");
            body.withChargeInfo(chargeInfobody);
            request.withBody(body);
            try {
                CreateGaussMySqlInstanceResponse response = client.createGaussMySqlInstance(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 将备份文件恢复到按需计费的新实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.gaussdb.v3.region.GaussDBRegion;
    import com.huaweicloud.sdk.gaussdb.v3.*;
    import com.huaweicloud.sdk.gaussdb.v3.model.*;
    
    
    public class CreateGaussMySqlInstanceSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            GaussDBClient client = GaussDBClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(GaussDBRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateGaussMySqlInstanceRequest request = new CreateGaussMySqlInstanceRequest();
            MysqlInstanceRequest body = new MysqlInstanceRequest();
            MysqlRestorePoint restorePointbody = new MysqlRestorePoint();
            restorePointbody.withSourceInstanceId("7033e7c3cf93438797d44ad7ae0a7d95in07")
                .withBackupId("7ffbf305376b4cbea0ae491257b6aaf9br07")
                .withType("backup");
            MysqlBackupStrategy backupStrategybody = new MysqlBackupStrategy();
            backupStrategybody.withStartTime("08:00-09:00");
            MysqlDatastoreInReq datastorebody = new MysqlDatastoreInReq();
            datastorebody.withType("gaussdb-mysql")
                .withVersion("8.0");
            MysqlChargeInfo chargeInfobody = new MysqlChargeInfo();
            chargeInfobody.withChargeMode(MysqlChargeInfo.ChargeModeEnum.fromValue("postPaid"));
            body.withRestorePoint(restorePointbody);
            body.withEnterpriseProjectId("0");
            body.withSlaveCount(1);
            body.withAvailabilityZoneMode("single");
            body.withBackupStrategy(backupStrategybody);
            body.withPassword("***");
            body.withConfigurationId("43570e0de32e40c5a15f831aa5ce4176pr07");
            body.withSecurityGroupId("fc577a1a-f202-424a-977f-24faec3fdd55");
            body.withSubnetId("c1cfa53c-65d3-431e-8552-326bf310c7ad");
            body.withVpcId("3cedfc54-b105-4652-a4e0-847b11576b58");
            body.withFlavorRef("gaussdb.mysql.xlarge.arm.4");
            body.withMode("Cluster");
            body.withDatastore(datastorebody);
            body.withName("gaussdb-mysql-instance2");
            body.withRegion("br-iaas-odin1");
            body.withChargeInfo(chargeInfobody);
            request.withBody(body);
            try {
                CreateGaussMySqlInstanceResponse response = client.createGaussMySqlInstance(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 按时间点恢复到按需计费的新实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.gaussdb.v3.region.GaussDBRegion;
    import com.huaweicloud.sdk.gaussdb.v3.*;
    import com.huaweicloud.sdk.gaussdb.v3.model.*;
    
    
    public class CreateGaussMySqlInstanceSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            GaussDBClient client = GaussDBClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(GaussDBRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateGaussMySqlInstanceRequest request = new CreateGaussMySqlInstanceRequest();
            MysqlInstanceRequest body = new MysqlInstanceRequest();
            MysqlRestorePoint restorePointbody = new MysqlRestorePoint();
            restorePointbody.withRestoreTime(1673852043000L)
                .withSourceInstanceId("7033e7c3cf93438797d44ad7ae0a7d95in07")
                .withType("timestamp");
            MysqlBackupStrategy backupStrategybody = new MysqlBackupStrategy();
            backupStrategybody.withStartTime("08:00-09:00");
            MysqlDatastoreInReq datastorebody = new MysqlDatastoreInReq();
            datastorebody.withType("gaussdb-mysql")
                .withVersion("8.0");
            MysqlChargeInfo chargeInfobody = new MysqlChargeInfo();
            chargeInfobody.withChargeMode(MysqlChargeInfo.ChargeModeEnum.fromValue("postPaid"));
            body.withRestorePoint(restorePointbody);
            body.withEnterpriseProjectId("0");
            body.withSlaveCount(1);
            body.withAvailabilityZoneMode("single");
            body.withBackupStrategy(backupStrategybody);
            body.withPassword("***");
            body.withConfigurationId("43570e0de32e40c5a15f831aa5ce4176pr07");
            body.withSecurityGroupId("fc577a1a-f202-424a-977f-24faec3fdd55");
            body.withSubnetId("c1cfa53c-65d3-431e-8552-326bf310c7ad");
            body.withVpcId("3cedfc54-b105-4652-a4e0-847b11576b58");
            body.withFlavorRef("gaussdb.mysql.xlarge.arm.4");
            body.withMode("Cluster");
            body.withDatastore(datastorebody);
            body.withName("gaussdb-mysql-instance3");
            body.withRegion("br-iaas-odin1");
            body.withChargeInfo(chargeInfobody);
            request.withBody(body);
            try {
                CreateGaussMySqlInstanceResponse response = client.createGaussMySqlInstance(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 创建周期为一个月的包年/包月实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.gaussdb.v3.region.GaussDBRegion;
    import com.huaweicloud.sdk.gaussdb.v3.*;
    import com.huaweicloud.sdk.gaussdb.v3.model.*;
    
    
    public class CreateGaussMySqlInstanceSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            GaussDBClient client = GaussDBClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(GaussDBRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateGaussMySqlInstanceRequest request = new CreateGaussMySqlInstanceRequest();
            MysqlInstanceRequest body = new MysqlInstanceRequest();
            MysqlRestorePoint restorePointbody = new MysqlRestorePoint();
            restorePointbody.withRestoreTime(1673852043000L)
                .withSourceInstanceId("7033e7c3cf93438797d44ad7ae0a7d95in07")
                .withType("timestamp");
            MysqlVolume volumebody = new MysqlVolume();
            volumebody.withSize("10");
            MysqlBackupStrategy backupStrategybody = new MysqlBackupStrategy();
            backupStrategybody.withStartTime("08:00-09:00");
            MysqlDatastoreInReq datastorebody = new MysqlDatastoreInReq();
            datastorebody.withType("gaussdb-mysql")
                .withVersion("8.0");
            MysqlChargeInfo chargeInfobody = new MysqlChargeInfo();
            chargeInfobody.withChargeMode(MysqlChargeInfo.ChargeModeEnum.fromValue("prePaid"))
                .withPeriodType(MysqlChargeInfo.PeriodTypeEnum.fromValue("month"))
                .withPeriodNum(1)
                .withIsAutoRenew("false")
                .withIsAutoPay("true");
            body.withRestorePoint(restorePointbody);
            body.withEnterpriseProjectId("0");
            body.withVolume(volumebody);
            body.withSlaveCount(1);
            body.withAvailabilityZoneMode("single");
            body.withBackupStrategy(backupStrategybody);
            body.withPassword("***");
            body.withConfigurationId("43570e0de32e40c5a15f831aa5ce4176pr07");
            body.withSecurityGroupId("fc577a1a-f202-424a-977f-24faec3fdd55");
            body.withSubnetId("c1cfa53c-65d3-431e-8552-326bf310c7ad");
            body.withVpcId("3cedfc54-b105-4652-a4e0-847b11576b58");
            body.withFlavorRef("gaussdb.mysql.xlarge.arm.4");
            body.withMode("Cluster");
            body.withDatastore(datastorebody);
            body.withName("gaussdb-mysql-instance4");
            body.withRegion("br-iaas-odin1");
            body.withChargeInfo(chargeInfobody);
            request.withBody(body);
            try {
                CreateGaussMySqlInstanceResponse response = client.createGaussMySqlInstance(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    

Python

  • 创建计费模式为按需计费,自动备份开始时间是08:00-09:00的实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkgaussdb.v3.region.gaussdb_region import GaussDBRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkgaussdb.v3 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = GaussDBClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(GaussDBRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateGaussMySqlInstanceRequest()
            backupStrategybody = MysqlBackupStrategy(
                start_time="08:00-09:00"
            )
            datastorebody = MysqlDatastoreInReq(
                type="gaussdb-mysql",
                version="8.0"
            )
            chargeInfobody = MysqlChargeInfo(
                charge_mode="postPaid"
            )
            request.body = MysqlInstanceRequest(
                enterprise_project_id="0",
                slave_count=1,
                availability_zone_mode="single",
                backup_strategy=backupStrategybody,
                password="***",
                configuration_id="43570e0de32e40c5a15f831aa5ce4176pr07",
                security_group_id="fc577a1a-f202-424a-977f-24faec3fdd55",
                subnet_id="c1cfa53c-65d3-431e-8552-326bf310c7ad",
                vpc_id="3cedfc54-b105-4652-a4e0-847b11576b58",
                flavor_ref="gaussdb.mysql.xlarge.arm.4",
                mode="Cluster",
                datastore=datastorebody,
                name="gaussdb-mysql-instance1",
                region="br-iaas-odin1",
                charge_info=chargeInfobody
            )
            response = client.create_gauss_my_sql_instance(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 将备份文件恢复到按需计费的新实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkgaussdb.v3.region.gaussdb_region import GaussDBRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkgaussdb.v3 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = GaussDBClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(GaussDBRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateGaussMySqlInstanceRequest()
            restorePointbody = MysqlRestorePoint(
                source_instance_id="7033e7c3cf93438797d44ad7ae0a7d95in07",
                backup_id="7ffbf305376b4cbea0ae491257b6aaf9br07",
                type="backup"
            )
            backupStrategybody = MysqlBackupStrategy(
                start_time="08:00-09:00"
            )
            datastorebody = MysqlDatastoreInReq(
                type="gaussdb-mysql",
                version="8.0"
            )
            chargeInfobody = MysqlChargeInfo(
                charge_mode="postPaid"
            )
            request.body = MysqlInstanceRequest(
                restore_point=restorePointbody,
                enterprise_project_id="0",
                slave_count=1,
                availability_zone_mode="single",
                backup_strategy=backupStrategybody,
                password="***",
                configuration_id="43570e0de32e40c5a15f831aa5ce4176pr07",
                security_group_id="fc577a1a-f202-424a-977f-24faec3fdd55",
                subnet_id="c1cfa53c-65d3-431e-8552-326bf310c7ad",
                vpc_id="3cedfc54-b105-4652-a4e0-847b11576b58",
                flavor_ref="gaussdb.mysql.xlarge.arm.4",
                mode="Cluster",
                datastore=datastorebody,
                name="gaussdb-mysql-instance2",
                region="br-iaas-odin1",
                charge_info=chargeInfobody
            )
            response = client.create_gauss_my_sql_instance(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 按时间点恢复到按需计费的新实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkgaussdb.v3.region.gaussdb_region import GaussDBRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkgaussdb.v3 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = GaussDBClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(GaussDBRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateGaussMySqlInstanceRequest()
            restorePointbody = MysqlRestorePoint(
                restore_time=1673852043000,
                source_instance_id="7033e7c3cf93438797d44ad7ae0a7d95in07",
                type="timestamp"
            )
            backupStrategybody = MysqlBackupStrategy(
                start_time="08:00-09:00"
            )
            datastorebody = MysqlDatastoreInReq(
                type="gaussdb-mysql",
                version="8.0"
            )
            chargeInfobody = MysqlChargeInfo(
                charge_mode="postPaid"
            )
            request.body = MysqlInstanceRequest(
                restore_point=restorePointbody,
                enterprise_project_id="0",
                slave_count=1,
                availability_zone_mode="single",
                backup_strategy=backupStrategybody,
                password="***",
                configuration_id="43570e0de32e40c5a15f831aa5ce4176pr07",
                security_group_id="fc577a1a-f202-424a-977f-24faec3fdd55",
                subnet_id="c1cfa53c-65d3-431e-8552-326bf310c7ad",
                vpc_id="3cedfc54-b105-4652-a4e0-847b11576b58",
                flavor_ref="gaussdb.mysql.xlarge.arm.4",
                mode="Cluster",
                datastore=datastorebody,
                name="gaussdb-mysql-instance3",
                region="br-iaas-odin1",
                charge_info=chargeInfobody
            )
            response = client.create_gauss_my_sql_instance(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建周期为一个月的包年/包月实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkgaussdb.v3.region.gaussdb_region import GaussDBRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkgaussdb.v3 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = GaussDBClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(GaussDBRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateGaussMySqlInstanceRequest()
            restorePointbody = MysqlRestorePoint(
                restore_time=1673852043000,
                source_instance_id="7033e7c3cf93438797d44ad7ae0a7d95in07",
                type="timestamp"
            )
            volumebody = MysqlVolume(
                size="10"
            )
            backupStrategybody = MysqlBackupStrategy(
                start_time="08:00-09:00"
            )
            datastorebody = MysqlDatastoreInReq(
                type="gaussdb-mysql",
                version="8.0"
            )
            chargeInfobody = MysqlChargeInfo(
                charge_mode="prePaid",
                period_type="month",
                period_num=1,
                is_auto_renew="false",
                is_auto_pay="true"
            )
            request.body = MysqlInstanceRequest(
                restore_point=restorePointbody,
                enterprise_project_id="0",
                volume=volumebody,
                slave_count=1,
                availability_zone_mode="single",
                backup_strategy=backupStrategybody,
                password="***",
                configuration_id="43570e0de32e40c5a15f831aa5ce4176pr07",
                security_group_id="fc577a1a-f202-424a-977f-24faec3fdd55",
                subnet_id="c1cfa53c-65d3-431e-8552-326bf310c7ad",
                vpc_id="3cedfc54-b105-4652-a4e0-847b11576b58",
                flavor_ref="gaussdb.mysql.xlarge.arm.4",
                mode="Cluster",
                datastore=datastorebody,
                name="gaussdb-mysql-instance4",
                region="br-iaas-odin1",
                charge_info=chargeInfobody
            )
            response = client.create_gauss_my_sql_instance(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    

Go

  • 创建计费模式为按需计费,自动备份开始时间是08:00-09:00的实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        gaussdb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := gaussdb.NewGaussDBClient(
            gaussdb.GaussDBClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateGaussMySqlInstanceRequest{}
    	backupStrategybody := &model.MysqlBackupStrategy{
    		StartTime: "08:00-09:00",
    	}
    	datastorebody := &model.MysqlDatastoreInReq{
    		Type: "gaussdb-mysql",
    		Version: "8.0",
    	}
    	chargeInfobody := &model.MysqlChargeInfo{
    		ChargeMode: model.GetMysqlChargeInfoChargeModeEnum().POST_PAID,
    	}
    	enterpriseProjectIdMysqlInstanceRequest:= "0"
    	configurationIdMysqlInstanceRequest:= "43570e0de32e40c5a15f831aa5ce4176pr07"
    	securityGroupIdMysqlInstanceRequest:= "fc577a1a-f202-424a-977f-24faec3fdd55"
    	request.Body = &model.MysqlInstanceRequest{
    		EnterpriseProjectId: &enterpriseProjectIdMysqlInstanceRequest,
    		SlaveCount: int32(1),
    		AvailabilityZoneMode: "single",
    		BackupStrategy: backupStrategybody,
    		Password: "***",
    		ConfigurationId: &configurationIdMysqlInstanceRequest,
    		SecurityGroupId: &securityGroupIdMysqlInstanceRequest,
    		SubnetId: "c1cfa53c-65d3-431e-8552-326bf310c7ad",
    		VpcId: "3cedfc54-b105-4652-a4e0-847b11576b58",
    		FlavorRef: "gaussdb.mysql.xlarge.arm.4",
    		Mode: "Cluster",
    		Datastore: datastorebody,
    		Name: "gaussdb-mysql-instance1",
    		Region: "br-iaas-odin1",
    		ChargeInfo: chargeInfobody,
    	}
    	response, err := client.CreateGaussMySqlInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 将备份文件恢复到按需计费的新实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        gaussdb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := gaussdb.NewGaussDBClient(
            gaussdb.GaussDBClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateGaussMySqlInstanceRequest{}
    	backupIdRestorePoint:= "7ffbf305376b4cbea0ae491257b6aaf9br07"
    	typeRestorePoint:= "backup"
    	restorePointbody := &model.MysqlRestorePoint{
    		SourceInstanceId: "7033e7c3cf93438797d44ad7ae0a7d95in07",
    		BackupId: &backupIdRestorePoint,
    		Type: &typeRestorePoint,
    	}
    	backupStrategybody := &model.MysqlBackupStrategy{
    		StartTime: "08:00-09:00",
    	}
    	datastorebody := &model.MysqlDatastoreInReq{
    		Type: "gaussdb-mysql",
    		Version: "8.0",
    	}
    	chargeInfobody := &model.MysqlChargeInfo{
    		ChargeMode: model.GetMysqlChargeInfoChargeModeEnum().POST_PAID,
    	}
    	enterpriseProjectIdMysqlInstanceRequest:= "0"
    	configurationIdMysqlInstanceRequest:= "43570e0de32e40c5a15f831aa5ce4176pr07"
    	securityGroupIdMysqlInstanceRequest:= "fc577a1a-f202-424a-977f-24faec3fdd55"
    	request.Body = &model.MysqlInstanceRequest{
    		RestorePoint: restorePointbody,
    		EnterpriseProjectId: &enterpriseProjectIdMysqlInstanceRequest,
    		SlaveCount: int32(1),
    		AvailabilityZoneMode: "single",
    		BackupStrategy: backupStrategybody,
    		Password: "***",
    		ConfigurationId: &configurationIdMysqlInstanceRequest,
    		SecurityGroupId: &securityGroupIdMysqlInstanceRequest,
    		SubnetId: "c1cfa53c-65d3-431e-8552-326bf310c7ad",
    		VpcId: "3cedfc54-b105-4652-a4e0-847b11576b58",
    		FlavorRef: "gaussdb.mysql.xlarge.arm.4",
    		Mode: "Cluster",
    		Datastore: datastorebody,
    		Name: "gaussdb-mysql-instance2",
    		Region: "br-iaas-odin1",
    		ChargeInfo: chargeInfobody,
    	}
    	response, err := client.CreateGaussMySqlInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 按时间点恢复到按需计费的新实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        gaussdb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := gaussdb.NewGaussDBClient(
            gaussdb.GaussDBClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateGaussMySqlInstanceRequest{}
    	restoreTimeRestorePoint:= int64(1673852043000)
    	typeRestorePoint:= "timestamp"
    	restorePointbody := &model.MysqlRestorePoint{
    		RestoreTime: &restoreTimeRestorePoint,
    		SourceInstanceId: "7033e7c3cf93438797d44ad7ae0a7d95in07",
    		Type: &typeRestorePoint,
    	}
    	backupStrategybody := &model.MysqlBackupStrategy{
    		StartTime: "08:00-09:00",
    	}
    	datastorebody := &model.MysqlDatastoreInReq{
    		Type: "gaussdb-mysql",
    		Version: "8.0",
    	}
    	chargeInfobody := &model.MysqlChargeInfo{
    		ChargeMode: model.GetMysqlChargeInfoChargeModeEnum().POST_PAID,
    	}
    	enterpriseProjectIdMysqlInstanceRequest:= "0"
    	configurationIdMysqlInstanceRequest:= "43570e0de32e40c5a15f831aa5ce4176pr07"
    	securityGroupIdMysqlInstanceRequest:= "fc577a1a-f202-424a-977f-24faec3fdd55"
    	request.Body = &model.MysqlInstanceRequest{
    		RestorePoint: restorePointbody,
    		EnterpriseProjectId: &enterpriseProjectIdMysqlInstanceRequest,
    		SlaveCount: int32(1),
    		AvailabilityZoneMode: "single",
    		BackupStrategy: backupStrategybody,
    		Password: "***",
    		ConfigurationId: &configurationIdMysqlInstanceRequest,
    		SecurityGroupId: &securityGroupIdMysqlInstanceRequest,
    		SubnetId: "c1cfa53c-65d3-431e-8552-326bf310c7ad",
    		VpcId: "3cedfc54-b105-4652-a4e0-847b11576b58",
    		FlavorRef: "gaussdb.mysql.xlarge.arm.4",
    		Mode: "Cluster",
    		Datastore: datastorebody,
    		Name: "gaussdb-mysql-instance3",
    		Region: "br-iaas-odin1",
    		ChargeInfo: chargeInfobody,
    	}
    	response, err := client.CreateGaussMySqlInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建周期为一个月的包年/包月实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        gaussdb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := gaussdb.NewGaussDBClient(
            gaussdb.GaussDBClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateGaussMySqlInstanceRequest{}
    	restoreTimeRestorePoint:= int64(1673852043000)
    	typeRestorePoint:= "timestamp"
    	restorePointbody := &model.MysqlRestorePoint{
    		RestoreTime: &restoreTimeRestorePoint,
    		SourceInstanceId: "7033e7c3cf93438797d44ad7ae0a7d95in07",
    		Type: &typeRestorePoint,
    	}
    	volumebody := &model.MysqlVolume{
    		Size: "10",
    	}
    	backupStrategybody := &model.MysqlBackupStrategy{
    		StartTime: "08:00-09:00",
    	}
    	datastorebody := &model.MysqlDatastoreInReq{
    		Type: "gaussdb-mysql",
    		Version: "8.0",
    	}
    	periodTypeChargeInfo:= model.GetMysqlChargeInfoPeriodTypeEnum().MONTH
    	periodNumChargeInfo:= int32(1)
    	isAutoRenewChargeInfo:= "false"
    	isAutoPayChargeInfo:= "true"
    	chargeInfobody := &model.MysqlChargeInfo{
    		ChargeMode: model.GetMysqlChargeInfoChargeModeEnum().PRE_PAID,
    		PeriodType: &periodTypeChargeInfo,
    		PeriodNum: &periodNumChargeInfo,
    		IsAutoRenew: &isAutoRenewChargeInfo,
    		IsAutoPay: &isAutoPayChargeInfo,
    	}
    	enterpriseProjectIdMysqlInstanceRequest:= "0"
    	configurationIdMysqlInstanceRequest:= "43570e0de32e40c5a15f831aa5ce4176pr07"
    	securityGroupIdMysqlInstanceRequest:= "fc577a1a-f202-424a-977f-24faec3fdd55"
    	request.Body = &model.MysqlInstanceRequest{
    		RestorePoint: restorePointbody,
    		EnterpriseProjectId: &enterpriseProjectIdMysqlInstanceRequest,
    		Volume: volumebody,
    		SlaveCount: int32(1),
    		AvailabilityZoneMode: "single",
    		BackupStrategy: backupStrategybody,
    		Password: "***",
    		ConfigurationId: &configurationIdMysqlInstanceRequest,
    		SecurityGroupId: &securityGroupIdMysqlInstanceRequest,
    		SubnetId: "c1cfa53c-65d3-431e-8552-326bf310c7ad",
    		VpcId: "3cedfc54-b105-4652-a4e0-847b11576b58",
    		FlavorRef: "gaussdb.mysql.xlarge.arm.4",
    		Mode: "Cluster",
    		Datastore: datastorebody,
    		Name: "gaussdb-mysql-instance4",
    		Region: "br-iaas-odin1",
    		ChargeInfo: chargeInfobody,
    	}
    	response, err := client.CreateGaussMySqlInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

更多

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

201

Success.

400

Client error.

500

Server error.

错误码

请参见错误码

相关文档