You need to enable JavaScript to run this app.
RDS for MySQL

RDS for MySQL

Copy page
Download PDF
Python SDK
Code examples
Copy page
Download PDF
Code examples
The code examples for the RDS for MySQL Python SDK in this topic are for reference only.​
Prerequisites​
Configure the request timeout​
By default, there is no timeout limit when you use the SDK to call MySQL APIs. You can add the _request_timeout parameter to an API call to specify a timeout period in seconds. If the request is not completed within the specified period, the request immediately terminates and returns a timeout error. For example, when you call the DescribeDBInstances API, you can use the following code to set the timeout period to 10 seconds.​
​
resp = api_instance.describe_db_instance(​
volcenginesdkrdsmysqlv2.DescribeDBInstanceRequest(​
instance_id="mysql-",​
_configuration=configuration,​
),​
_request_timeout=10​
)​
​
Create a MySQL instance​
For the definitions, value ranges, and other information about the parameters used in the following SDK code, refer to 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)​
​
​
The following table describes the parameters in this example.​
​
Configuration item​
Description​
Value​
DBEngineVersion​
Instance name.​
Your Instance Name​
NodeInfo​
The specifications of the instance.​
[​
{​
"NodeType": "Primary",​
"ZoneId": "cn-beijing-a",​
"NodeSpec": "rds.mysql.1c2g"​
},​
{​
"NodeType": "Secondary",​
"ZoneId": "cn-beijing-a",​
"NodeSpec": "rds.mysql.1c2g"​
},​
{​
"NodeType": "ReadOnly",​
"ZoneId": "cn-beijing-a",​
"NodeSpec": "rds.mysql.1c2g"​
}​
]​
StorageType​
The storage type of the instance.​
LocalSSD​
StorageSpace​
The storage space for the instance.​
100​
VpcId​
Proprietary network (VPC) ID.​
vpc-****​
SubnetId​
Subnet ID.​
Subnet123456​
InstanceName​
Instance name.​
Your Instance Name​
SuperAccountName​
Super account name.​
Test1​
SuperAccountPassword​
Password for the super account.​
Test@123456​
LowerCaseTableNames​
Whether table names are case sensitive.​
1​
DBTimeZone​
Time zone.​
UTC +08:00​
DBParamGroupId​
Parameter templates ID.​
ParamGroup123456​
ProjectName​
The project to which the instance belongs.​
Test​
ChargeInfo​
Billing method.​
{​
"ChargeType": "PostPaid"​
}​
InstanceTags​
Instance tag.​
{​
"Key": ""aa,​
"Value":"aa"​
}​
Number​
The number of instances to purchase.​
1​
​
Query MySQL instance summary​
​
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)​
​
​
Last updated: 2025.12.04 11:25:46