本文提供的云数据库 MySQL 版 Python SDK 的代码示例仅供参考。
使用 SDK 调用 MySQL 接口时,默认无超时时间限制。您可以在发起接口调用请求时,在代码的最后加上 _request_timeout
参数指定请求的超时时间(单位:秒),若未在该时间内完成,请求会立即终止并报超时错误。例如,您可以在调用 DescribeDBInstances 接口时,通过以下代码设置超时时间为 10 秒。
resp = api_instance.describe_db_instance( volcenginesdkrdsmysqlv2.DescribeDBInstanceRequest( instance_id="mysql-", _configuration=configuration, ), _request_timeout=10 )
关于下述 SDK 代码中使用的参数的定义、取值范围等信息,请参见 CreateDBInstance。
from pprint import pprint import volcenginesdkrdsmysqlv2 import volcenginesdkcore from volcenginesdkcore.rest import ApiException if __name__ == "__main__": configuration = volcenginesdkcore.Configuration() configuration.ak = "Your AK" configuration.sk = "Your SK" configuration.region = "Your Region" try: api_instance = volcenginesdkrdsmysqlv2.RDSMYSQLV2Api(volcenginesdkcore.ApiClient(configuration)) resp = api_instance.create_db_instance(volcenginesdkrdsmysqlv2.CreateDBInstanceRequest( db_engine_version="MySQL_5_7", node_info=[ { "NodeType": "Primary", "ZoneId": "cn-beijing-a", "NodeSpec": "rds.mysql.1c2g", }, { "NodeType": "Secondary", "ZoneId": "cn-beijing-a", "NodeSpec": "rds.mysql.1c2g", }, ], storage_type="LocalSSD", storage_space=100, vpc_id="vpc-****", subnet_id="subnet-****", charge_info={ "ChargeType": "PostPaid" }, _configuration=configuration, )) pprint(resp) except ApiException as e: print("Exception: %s\n" % e)
本示例中的参数说明如下表所示。
配置项 | 说明 | 取值 |
---|---|---|
DBEngineVersion | 实例名称。 | Your Instance Name |
NodeInfo | 实例规格配置。 | [ |
StorageType | 实例存储类型。 | LocalSSD |
StorageSpace | 实例存储空间。 | 100 |
VpcId | 专有网络(VPC) ID。 | vpc-**** |
SubnetId | 子网 ID。 | Subnet123456 |
InstanceName | 实例名称。 | Your Instance Name |
SuperAccountName | 高权限账号名称。 | Test1 |
SuperAccountPassword | 高权限账号的密码。 | Test@123456 |
LowerCaseTableNames | 表名是否区分大小写。 | 1 |
DBTimeZone | 时区。 | UTC +08:00 |
DBParamGroupId | 参数模板 ID。 | ParamGroup123456 |
ProjectName | 实例所属项目。 | Test |
ChargeInfo | 计费类型。 | { |
InstanceTags | 实例标签。 | { |
Number | 实例购买数量。 | 1 |
from pprint import pprint import volcenginesdkrdsmysqlv2 import volcenginesdkcore from volcenginesdkcore.rest import ApiException if __name__ == "__main__": configuration = volcenginesdkcore.Configuration() configuration.ak = "Your AK" configuration.sk = "Your SK" configuration.region = "Your Region" try: # 创建 RDS MySQL SDK 客户端,接口调用均需要通过此客户端执行 api_instance = volcenginesdkrdsmysqlv2.RDSMYSQLV2Api(volcenginesdkcore.ApiClient(configuration)) resp = api_instance.describe_db_instance_detail( volcenginesdkrdsmysqlv2.DescribeDBInstanceDetailRequest( instance_id="Your InstanceId", ) ) print(resp) except ApiException as e: print("Exception: %s\n" % e)