

# RDS 프록시 명령줄 예제
<a name="rds-proxy.examples"></a>

 연결 명령과 SQL 문의 조합이 어떻게 RDS Proxy와 상호 작용하는지 보려면 다음 예제를 살펴보십시오.

**예제**
+  [Preserving Connections to a MySQL Database Across a Failover](#example-mysql-preserve-connections) 
+  [Adjusting the max_connections Setting for an Aurora DB Cluster](#example-adjust-cluster-max-connections) 

**Example 장애 조치 전반에 걸쳐 MySQL 데이터베이스에 대한 연결 유지**  
 이 MySQL 예에서는 장애 조치 중에 어떻게 열린 연결이 계속 작동하는지 보여줍니다. 데이터베이스를 재부팅하거나 데이터베이스가 문제로 인해 사용할 수 없게 되는 경우를 예로 들 수 있습니다. 이 예제에서는 `the-proxy`라는 프록시와 DB 인스턴스 `instance-8898` 및 `instance-9814`가 있는 Aurora DB 클러스터를 사용합니다. Linux 명령줄에서 `failover-db-cluster` 명령을 실행하면 프록시와 연결된 라이터 인스턴스가 다른 DB 인스턴스로 변경됩니다. 연결이 열려 있는 상태에서 프록시와 연결된 DB 인스턴스가 변경되는 것을 확인할 수 있습니다.  

```
$ mysql -h the-proxy.proxy-demo.us-east-1.rds.amazonaws.com -u admin_user -p
Enter password:
...

mysql> select @@aurora_server_id;
+--------------------+
| @@aurora_server_id |
+--------------------+
| instance-9814      |
+--------------------+
1 row in set (0.01 sec)

mysql>
[1]+  Stopped                 mysql -h the-proxy.proxy-demo.us-east-1.rds.amazonaws.com -u admin_user -p
$ # Initially, instance-9814 is the writer.
$ aws rds failover-db-cluster --db-cluster-identifier cluster-56-2019-11-14-1399
JSON output
$ # After a short time, the console shows that the failover operation is complete.
$ # Now instance-8898 is the writer.
$ fg
mysql -h the-proxy.proxy-demo.us.us-east-1.rds.amazonaws.com -u admin_user -p

mysql> select @@aurora_server_id;
+--------------------+
| @@aurora_server_id |
+--------------------+
| instance-8898      |
+--------------------+
1 row in set (0.01 sec)

mysql>
[1]+  Stopped                 mysql -h the-proxy.proxy-demo.us-east-1.rds.amazonaws.com -u admin_user -p
$ aws rds failover-db-cluster --db-cluster-identifier cluster-56-2019-11-14-1399
JSON output
$ # After a short time, the console shows that the failover operation is complete.
$ # Now instance-9814 is the writer again.
$ fg
mysql -h the-proxy.proxy-demo.us-east-1.rds.amazonaws.com -u admin_user -p

mysql> select @@aurora_server_id;
+--------------------+
| @@aurora_server_id |
+--------------------+
| instance-9814      |
+--------------------+
1 row in set (0.01 sec)
+---------------+---------------+
| Variable_name | Value         |
+---------------+---------------+
| hostname      | ip-10-1-3-178 |
+---------------+---------------+
1 row in set (0.02 sec)
```

**Example Aurora DB 클러스터에 대한 max\$1connections 설정 조정**  
 이 예제에서는 Aurora MySQL DB 클러스터의 `max_connections` 설정을 조정하는 방법을 보여 줍니다. 이렇게 하려면 MySQL 5.7과 호환되는 클러스터의 기본 파라미터 설정을 기반으로 자체 DB 클러스터 파라미터 그룹을 생성합니다. `max_connections` 설정에 값을 지정하여 기본값을 설정하는 공식을 재지정합니다. DB 클러스터 파라미터 그룹을 자체 DB 클러스터와 연결합니다.  

```
export REGION=us-east-1
export CLUSTER_PARAM_GROUP=rds-proxy-mysql-57-max-connections-demo
export CLUSTER_NAME=rds-proxy-mysql-57

aws rds create-db-parameter-group --region $REGION \
  --db-parameter-group-family aurora-mysql5.7 \
  --db-parameter-group-name $CLUSTER_PARAM_GROUP \
  --description "Aurora MySQL 5.7 cluster parameter group for RDS Proxy demo."

aws rds modify-db-cluster --region $REGION \
  --db-cluster-identifier $CLUSTER_NAME \
  --db-cluster-parameter-group-name $CLUSTER_PARAM_GROUP

echo "New cluster param group is assigned to cluster:"
aws rds describe-db-clusters --region $REGION \
  --db-cluster-identifier $CLUSTER_NAME \
  --query '*[*].{DBClusterParameterGroup:DBClusterParameterGroup}'

echo "Current value for max_connections:"
aws rds describe-db-cluster-parameters --region $REGION \
  --db-cluster-parameter-group-name $CLUSTER_PARAM_GROUP \
  --query '*[*].{ParameterName:ParameterName,ParameterValue:ParameterValue}' \
  --output text | grep "^max_connections"

echo -n "Enter number for max_connections setting: "
read answer

aws rds modify-db-cluster-parameter-group --region $REGION --db-cluster-parameter-group-name $CLUSTER_PARAM_GROUP \
  --parameters "ParameterName=max_connections,ParameterValue=$$answer,ApplyMethod=immediate"

echo "Updated value for max_connections:"
aws rds describe-db-cluster-parameters --region $REGION \
  --db-cluster-parameter-group-name $CLUSTER_PARAM_GROUP \
  --query '*[*].{ParameterName:ParameterName,ParameterValue:ParameterValue}' \
  --output text | grep "^max_connections"
```