将 ModifyDBParameterGroup 与 Amazon SDK 或 CLI 配合使用 - Amazon Relational Database Service
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

ModifyDBParameterGroup 与 Amazon SDK 或 CLI 配合使用

以下代码示例演示如何使用 ModifyDBParameterGroup

操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:

.NET
Amazon SDK for .NET
注意

在 GitHub 上查看更多内容。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

/// <summary> /// Update a DB parameter group. Use the action DescribeDBParameterGroupsAsync /// to determine when the DB parameter group is ready to use. /// </summary> /// <param name="name">Name of the DB parameter group.</param> /// <param name="parameters">List of parameters. Maximum of 20 per request.</param> /// <returns>The updated DB parameter group name.</returns> public async Task<string> ModifyDBParameterGroup( string name, List<Parameter> parameters) { var response = await _amazonRDS.ModifyDBParameterGroupAsync( new ModifyDBParameterGroupRequest() { DBParameterGroupName = name, Parameters = parameters, }); return response.DBParameterGroupName; }
C++
适用于 C++ 的 SDK
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region (overrides config file). // clientConfig.region = "us-east-1"; Aws::RDS::RDSClient client(clientConfig); Aws::RDS::Model::ModifyDBParameterGroupRequest request; request.SetDBParameterGroupName(PARAMETER_GROUP_NAME); request.SetParameters(updateParameters); Aws::RDS::Model::ModifyDBParameterGroupOutcome outcome = client.ModifyDBParameterGroup(request); if (outcome.IsSuccess()) { std::cout << "The DB parameter group was successfully modified." << std::endl; } else { std::cerr << "Error with RDS::ModifyDBParameterGroup. " << outcome.GetError().GetMessage() << std::endl; }
CLI
Amazon CLI

修改数据库参数组

以下 modify-db-parameter-group 示例将更改数据库参数组中 clr enabled 参数的值。--apply-immediately 参数使数据库参数组得到立即修改,而不是等到下一个维护时段。

aws rds modify-db-parameter-group \ --db-parameter-group-name test-sqlserver-se-2017 \ --parameters "ParameterName='clr enabled',ParameterValue=1,ApplyMethod=immediate"

输出:

{ "DBParameterGroupName": "test-sqlserver-se-2017" }

有关更多信息,请参阅《Amazon RDS 用户指南》中的修改数据库参数组中的参数

Go
适用于 Go V2 的 SDK
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

type DbInstances struct { RdsClient *rds.Client } // UpdateParameters updates parameters in a named DB parameter group. func (instances *DbInstances) UpdateParameters(parameterGroupName string, params []types.Parameter) error { _, err := instances.RdsClient.ModifyDBParameterGroup(context.TODO(), &rds.ModifyDBParameterGroupInput{ DBParameterGroupName: aws.String(parameterGroupName), Parameters: params, }) if err != nil { log.Printf("Couldn't update parameters in %v: %v\n", parameterGroupName, err) return err } else { return nil } }
Java
SDK for Java 2.x
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

// Modify auto_increment_offset and auto_increment_increment parameters. public static void modifyDBParas(RdsClient rdsClient, String dbGroupName) { try { Parameter parameter1 = Parameter.builder() .parameterName("auto_increment_offset") .applyMethod("immediate") .parameterValue("5") .build(); List<Parameter> paraList = new ArrayList<>(); paraList.add(parameter1); ModifyDbParameterGroupRequest groupRequest = ModifyDbParameterGroupRequest.builder() .dbParameterGroupName(dbGroupName) .parameters(paraList) .build(); ModifyDbParameterGroupResponse response = rdsClient.modifyDBParameterGroup(groupRequest); System.out.println("The parameter group " + response.dbParameterGroupName() + " was successfully modified"); } catch (RdsException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } }
Python
SDK for Python(Boto3)
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

class InstanceWrapper: """Encapsulates Amazon RDS DB instance actions.""" def __init__(self, rds_client): """ :param rds_client: A Boto3 Amazon RDS client. """ self.rds_client = rds_client @classmethod def from_client(cls): """ Instantiates this class from a Boto3 client. """ rds_client = boto3.client("rds") return cls(rds_client) def update_parameters(self, parameter_group_name, update_parameters): """ Updates parameters in a custom DB parameter group. :param parameter_group_name: The name of the parameter group to update. :param update_parameters: The parameters to update in the group. :return: Data about the modified parameter group. """ try: response = self.rds_client.modify_db_parameter_group( DBParameterGroupName=parameter_group_name, Parameters=update_parameters ) except ClientError as err: logger.error( "Couldn't update parameters in %s. Here's why: %s: %s", parameter_group_name, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return response
  • 有关 API 详细信息,请参阅《适用于 Python 的 Amazon SDK(Boto3)API 参考》中的 ModifyDBParameterGroup

有关 Amazon SDK 开发人员指南和代码示例的完整列表,请参阅 将此服务与 Amazon SDK 结合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。