

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 Aurora 讀取複本，從 RDS for MySQL 資料庫執行個體將資料遷移至 Amazon Aurora MySQL 資料庫叢集
<a name="AuroraMySQL.Migrating.RDSMySQL.Replica"></a>

Aurora 使用 MySQL 資料庫引擎的二進位日誌複寫功能，為來源 RDS for MySQL 資料庫執行個體建立一種特殊類型的資料庫叢集，稱為 Aurora 讀取複本。對來源 RDS for MySQL 資料庫執行個體進行的更新會以非同步方式複寫至 Aurora 讀取複本。

我們建議使用此功能建立來源 RDS for MySQL 資料庫執行個體的 Aurora 讀取複本，以便從 RDS for MySQL 資料庫執行個體遷移至 Aurora MySQL 資料庫叢集。當 RDS for MySQL 資料庫執行個體和 Aurora 讀取複本之間的複本延遲為 0 時，您可以將用戶端應用程式引導至 Aurora 讀取複本，然後停止複寫，使 Aurora 讀取複本變成獨立的 Aurora MySQL 資料庫叢集。遷移需要一段時間，每個一兆位元組 (TiB) 資料大約需要幾個小時，請做好準備。

如需可使用 Aurora 的區域清單，請參閱 *AWS 一般參考* 中的 [Amazon Aurora](https://docs.aws.amazon.com/general/latest/gr/rande.html#aurora)。

當您建立 RDS for MySQL 資料庫執行個體的 Aurora 讀取複本時，Amazon RDS 會建立來源 RDS for MySQL 資料庫執行個體的資料庫快照 (為 Amazon RDS 私有，不會產生費用)。然後 Amazon RDS 會將資料從資料庫快照遷移至 Aurora 僅供讀取複本。當資料庫快照的資料遷移至新的 Aurora MySQL 資料庫叢集之後，Amazon RDS 會開始在 RDS for MySQL 資料庫執行個體和 Aurora MySQL 資料庫叢集之間複寫。如果 RDS for MySQL 資料庫執行個體中有資料表使用 InnoDB 以外的儲存引擎，或使用壓縮資料列格式，則在建立 Aurora 讀取複本之前，您可以更改這些資料表來使用 InnoDB 儲存引擎和動態資料列格式，使建立 Aurora 讀取複本的程序加快。如需將 MySQL 資料庫快照複製到 Aurora MySQL 資料庫叢集之程序的詳細資訊，請參閱[將資料從 RDS for MySQL 資料庫執行個體遷移到 Amazon Aurora MySQL 資料庫叢集](AuroraMySQL.Migrating.RDSMySQL.md)。

一個 RDS for MySQL 資料庫執行個體只能有一個 Aurora 讀取複本。

**注意**  
由於 Aurora MySQL 與 RDS for MySQL 資料庫執行個體 (複寫主節點) 的 MySQL 資料庫引擎版本之間的功能差異，複寫可能會出現問題。如果您遇到錯誤，您可以在 [Amazon RDS 社群論壇](https://forums.aws.amazon.com/forum.jspa?forumID=60)或聯絡 找到說明 AWS 支援。  
如果 RDS for MySQL 資料庫執行個體已是跨區域讀取複本的來源，您就無法建立 Aurora 讀取複本。  
您無法從某些較舊的 RDS for MySQL 8.0 版本 (包括 8.0.11、8.0.13 和 8.0.15) 遷移到 Aurora MySQL 版本 3.05 及更高版本。建議您在遷移之前，先升級至 RDS for MySQL 8.0.28 版。

如需 MySQL 僅供讀取複本的詳細資訊，請參閱[使用 MariaDB、MySQL 及 PostgreSQL DB 執行個體的僅供讀取複本](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html)。

## 建立 Aurora 僅供讀取複本
<a name="AuroraMySQL.Migrating.RDSMySQL.Replica.Create"></a>

您可以使用 主控台 AWS CLI、 或 RDS API，為 RDS for MySQL 資料庫執行個體建立 Aurora 僅供讀取複本。

### 主控台
<a name="AuroraMySQL.Migrating.RDSMySQL.Replica.Create.Console"></a>

**從來源 RDS for MySQL 資料庫執行個體建立 Aurora 讀取複本**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/)：// 開啟 Amazon RDS 主控台。

1. 在導覽窗格中，選擇 **Databases** (資料庫)。

1. 選擇要作為 Aurora 僅供讀取複本來源的 MySQL 資料庫執行個體。

1. 在 **Actions** (動作) 中選擇 **Create Aurora read replica** (建立僅供讀取複本)。

1. 選擇要用於 Aurora 僅供讀取複本的資料庫叢集規格，如下表所述。    
<a name="aurora_read_replica_param_advice"></a>[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Migrating.RDSMySQL.Replica.html)

1. 選擇 **Create read replica (建立僅供讀取複本)**。

### AWS CLI
<a name="AuroraMySQL.Migrating.RDSMySQL.Replica.Create.CLI"></a>

若要從來源 RDS for MySQL 資料庫執行個體建立 Aurora 僅供讀取複本，請使用 [https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-cluster.html](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-cluster.html)和 [https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html) AWS CLI 命令建立新的 Aurora MySQL 資料庫叢集。當您呼叫 `create-db-cluster` 命令時，請加上 `--replication-source-identifier` 參數，以識別來源 MySQL 資料庫執行個體的 Amazon Resource Name (ARN)。如需 Amazon RDS ARN 的詳細資訊，請參閱 [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#arn-syntax-rds)。

請勿指定主要使用者名稱、主要密碼或資料庫名稱，因為 Aurora 僅供讀取複本會使用與來源 MySQL 資料庫執行個體相同的主要使用者名稱、主要密碼、資料庫名稱。

對於 Linux、macOS 或 Unix：

```
aws rds create-db-cluster --db-cluster-identifier sample-replica-cluster --engine aurora \
    --db-subnet-group-name mysubnetgroup --vpc-security-group-ids sg-c7e5b0d2 \
    --replication-source-identifier arn:aws:rds:us-west-2:123456789012:db:primary-mysql-instance
```

在 Windows 中：

```
aws rds create-db-cluster --db-cluster-identifier sample-replica-cluster --engine aurora ^
    --db-subnet-group-name mysubnetgroup --vpc-security-group-ids sg-c7e5b0d2 ^
    --replication-source-identifier arn:aws:rds:us-west-2:123456789012:db:primary-mysql-instance
```

如果您使用主控台建立 Aurora 僅供讀取複本，則 Aurora 會為您的資料庫叢集 Aurora 僅供讀取複本自動建立主要執行個體。如果您使用 AWS CLI 建立 Aurora 僅供讀取複本，則必須明確建立資料庫叢集的主要執行個體。主要執行個體是資料庫叢集內第一個建立的執行個體。

您可以使用 [https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html) AWS CLI 命令搭配下列參數，為您的資料庫叢集建立主要執行個體。
+ `--db-cluster-identifier`

  資料庫叢集的名稱。
+ `--db-instance-class`

  要用於主要執行個體的執行個體類別名稱。
+ `--db-instance-identifier`

  主要執行個體的名稱。
+ `--engine aurora`

在此範例中，您會使用在 *myinstanceclass* 中指定的資料庫執行個體類別，為 *myreadreplicacluster* 資料庫叢集建立主要執行個體 *myreadreplicainstance*。

**Example**  
對於 Linux、macOS 或 Unix：  

```
aws rds create-db-instance \
    --db-cluster-identifier myreadreplicacluster \
    --db-instance-class myinstanceclass \
    --db-instance-identifier myreadreplicainstance \
    --engine aurora
```
在 Windows 中：  

```
aws rds create-db-instance ^
    --db-cluster-identifier myreadreplicacluster ^
    --db-instance-class myinstanceclass ^
    --db-instance-identifier myreadreplicainstance ^
    --engine aurora
```

### RDS API
<a name="Aurora.Migration.RDSMySQL.Create.API"></a>

若要從來源 RDS for MySQL 資料庫執行個體建立 Aurora 讀取複本，請使用 [https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBCluster.html](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBCluster.html) 和 [https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html) Amazon RDS API 命令建立新的 Aurora 資料庫叢集和主要執行個體。請勿指定主要使用者名稱、主要密碼或資料庫名稱，因為 Aurora 讀取複本會使用與來源 RDS for MySQL 資料庫執行個體相同的主要使用者名稱、主要密碼、資料庫名稱。

您可以使用 [https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBCluster.html](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBCluster.html) Amazon RDS API 命令搭配以下參數，從來源 RDS for MySQL 資料庫執行個體為 Aurora 讀取複本建立新的 Aurora 資料庫叢集：
+ `DBClusterIdentifier`

  要建立的資料庫叢集名稱。
+ `DBSubnetGroupName`

  要與此資料庫叢集關聯之資料庫子網路群組的名稱。
+ `Engine=aurora`
+ `KmsKeyId`

   AWS KMS key 選擇性地使用 加密資料庫叢集，取決於您的 MySQL 資料庫執行個體是否已加密。
  + 如果 MySQL 資料庫執行個體未加密，請指定加密金鑰，以便對資料庫叢集進行靜態加密。否則會使用您的帳戶的預設加密金鑰，對資料庫叢集進行靜態加密。
  + 如果 MySQL 資料庫執行個體已加密，請指定加密金鑰，以使用指定的加密金鑰對資料庫叢集進行靜態加密。否則會使用 MySQL 資料庫執行個體的加密金鑰，對資料庫叢集進行靜態加密。
**注意**  
您無法從已加密的 MySQL 資料庫執行個體來建立未加密的資料庫叢集。
+ `ReplicationSourceIdentifier`

  來源 MySQL 資料庫執行個體的 Amazon Resource Name (ARN)。如需 Amazon RDS ARN 的詳細資訊，請參閱 [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#arn-syntax-rds)。
+ `VpcSecurityGroupIds`

  要與此資料庫叢集關聯的 EC2 VPC 安全群組的清單。

在此範例中，您會從來源 MySQL 資料庫執行個體建立資料庫叢集 *myreadreplicacluster*，此來源的 ARN 設為 *mysqlprimaryARN*，並與 *mysubnetgroup* 資料庫子網路群組及 *mysecuritygroup* VPC 安全群組相關聯。

**Example**  

```
https://rds.us-east-1.amazonaws.com/
    ?Action=CreateDBCluster
    &DBClusterIdentifier=myreadreplicacluster
    &DBSubnetGroupName=mysubnetgroup
    &Engine=aurora
    &ReplicationSourceIdentifier=mysqlprimaryARN
    &SignatureMethod=HmacSHA256
    &SignatureVersion=4
    &Version=2014-10-31
    &VpcSecurityGroupIds=mysecuritygroup
    &X-Amz-Algorithm=AWS4-HMAC-SHA256
    &X-Amz-Credential=AKIADQKE4SARGYLE/20150927/us-east-1/rds/aws4_request
    &X-Amz-Date=20150927T164851Z
    &X-Amz-SignedHeaders=content-type;host;user-agent;x-amz-content-sha256;x-amz-date
    &X-Amz-Signature=6a8f4bd6a98f649c75ea04a6b3929ecc75ac09739588391cd7250f5280e716db
```

如果您使用主控台建立 Aurora 僅供讀取複本，則 Aurora 會為您的資料庫叢集 Aurora 僅供讀取複本自動建立主要執行個體。如果您使用 AWS CLI 建立 Aurora 僅供讀取複本，則必須明確建立資料庫叢集的主要執行個體。主要執行個體是資料庫叢集內第一個建立的執行個體。

您可以使用 [https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html) Amazon RDS API 命令搭配以下參數來建立資料庫叢集的主要執行個體：
+ `DBClusterIdentifier`

  資料庫叢集的名稱。
+ `DBInstanceClass`

  要用於主要執行個體的執行個體類別名稱。
+ `DBInstanceIdentifier`

  主要執行個體的名稱。
+ `Engine=aurora`

在此範例中，您會使用在 *myinstanceclass* 中指定的資料庫執行個體類別，為 *myreadreplicacluster* 資料庫叢集建立主要執行個體 *myreadreplicainstance*。

**Example**  

```
https://rds.us-east-1.amazonaws.com/
    ?Action=CreateDBInstance
    &DBClusterIdentifier=myreadreplicacluster
    &DBInstanceClass=myinstanceclass
    &DBInstanceIdentifier=myreadreplicainstance
    &Engine=aurora
    &SignatureMethod=HmacSHA256
    &SignatureVersion=4
    &Version=2014-09-01
    &X-Amz-Algorithm=AWS4-HMAC-SHA256
    &X-Amz-Credential=AKIADQKE4SARGYLE/20140424/us-east-1/rds/aws4_request
    &X-Amz-Date=20140424T194844Z
    &X-Amz-SignedHeaders=content-type;host;user-agent;x-amz-content-sha256;x-amz-date
    &X-Amz-Signature=bee4aabc750bf7dad0cd9e22b952bd6089d91e2a16592c2293e532eeaab8bc77
```

## 檢視 Aurora 僅供讀取複本
<a name="AuroraMySQL.Migrating.RDSMySQL.Replica.View"></a>

您可以使用 AWS 管理主控台 或 AWS CLI，以檢視 Aurora MySQL 資料庫叢集的 MySQL 至 Aurora MySQL 複寫關係。

### 主控台
<a name="AuroraMySQL.Migrating.RDSMySQL.Replica.View.Console"></a>

**檢視 Aurora 僅供讀取複本的主要 MySQL 資料庫執行個體**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/)：// 開啟 Amazon RDS 主控台。

1. 在導覽窗格中，選擇 **Databases** (資料庫)。

1. 選擇 Aurora 僅供讀取複本的資料庫叢集，以顯示其詳細資訊。主要 MySQL 資料庫執行個體資訊在 **Replication source** (複寫來源) 欄位中。  
![\[檢視 MySQL 主要資料庫\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/images/aurora-repl6.png)

### AWS CLI
<a name="AuroraMySQL.Migrating.RDSMySQL.Replica.View.CLI"></a>

若要使用 檢視 Aurora MySQL 資料庫叢集的 MySQL 對 Aurora MySQL 複寫關係 AWS CLI，請使用 [https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-clusters.html](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-clusters.html)和 [https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-instances.html](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-instances.html)命令。

若要判斷哪個 MySQL 資料庫執行個體是主節點，請使用 [https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-clusters.html](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-clusters.html)，並在 `--db-cluster-identifier` 選項中指定 Aurora 僅供讀取複本的叢集識別符。請查閱輸出中的 `ReplicationSourceIdentifier` 元素，以取得做為複寫主節點之資料庫執行個體的 ARN。

若要判斷哪個資料庫叢集是 Aurora 僅供讀取複本，請使用 [https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-instances.html](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-instances.html)，並在 `--db-instance-identifier` 選項中指定 MySQL 資料庫執行個體的執行個體識別符。請參閱輸出中的 `ReadReplicaDBClusterIdentifiers` 元素，以取得 Aurora 僅供讀取複本的資料庫叢集識別符。

**Example**  
對於 Linux、macOS 或 Unix：  

```
aws rds describe-db-clusters \
    --db-cluster-identifier myreadreplicacluster
```

```
aws rds describe-db-instances \
    --db-instance-identifier mysqlprimary
```
在 Windows 中：  

```
aws rds describe-db-clusters ^
    --db-cluster-identifier myreadreplicacluster
```

```
aws rds describe-db-instances ^
    --db-instance-identifier mysqlprimary
```

## 提升 Aurora 僅供讀取複本
<a name="AuroraMySQL.Migrating.RDSMySQL.Replica.Promote"></a>

遷移完成後，您可以使用 AWS 管理主控台 或 將 Aurora 僅供讀取複本提升為獨立的資料庫叢集 AWS CLI。

接著您可以將用戶端應用程式導向 Aurora 僅供讀取複本的端點。如需 Aurora 端點的詳細資訊，請參閱 [Amazon Aurora 端點連線](Aurora.Overview.Endpoints.md)。提升應該會很快完成，而且您在提升期間可以讀取和寫入 Aurora 僅供讀取複本。但在此期間，您無法刪除主要 MySQL 資料庫執行個體，或解除資料庫執行個體與 Aurora 僅供讀取複本之間的連結。

在提升 Aurora 僅供讀取複本之前，請先停止任何交易寫入來源 MySQL 資料庫執行個體，並等待 Aurora 僅供讀取複本的複本延遲達到 0。您可以檢視 Aurora 僅供讀取複本的複本延遲，方法是在您的 Aurora 僅供讀取複本上呼叫 `SHOW SLAVE STATUS` (Aurora MySQL 第 2 版) 或 `SHOW REPLICA STATUS` (Aurora MySQL 第 3 版) 命令。檢查 **Seconds behind master** 值。

當交易停止寫入主節點且複本延遲為 0 之後，您就可以開始寫入 Aurora 僅供讀取複本。如果您在此之前寫入 Aurora 僅供讀取複本，且修改 MySQL 主節點上也正在修改的資料表，則可能會中斷複寫至 Aurora 的作業。如果發生這種情況，您必須刪除並重新建立 Aurora 僅供讀取複本。

### 主控台
<a name="AuroraMySQL.Migrating.RDSMySQL.Replica.Promote.Console"></a>

**將 Aurora 僅供讀取複本提升為 Aurora 資料庫叢集**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/)：// 開啟 Amazon RDS 主控台。

1. 在導覽窗格中，選擇 **Databases** (資料庫)。

1. 選擇 Aurora 僅供讀取複本的資料庫叢集。

1. 針對 **Actions** (動作)，選擇 **Promote** (提升)。

1. 選擇 **Promote Read Replica** (提升僅供讀取複本)。

升級後，請使用下列程序確認提升已完成。

**確認已提升 Aurora 僅供讀取複本**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/)：// 開啟 Amazon RDS 主控台。

1. 在導覽窗格中，選擇 **Events** (事件)。

1. 在 **Events** (事件) 頁面上，確認您提升的叢集有 `Promoted Read Replica cluster to a stand-alone database cluster` 事件。

提升完成後，主要 MySQL 資料庫執行個體與 Aurora 僅供讀取複本會解除連結，您可以安心地刪除資料庫執行個體 (如果想要這麼做)。

### AWS CLI
<a name="AuroraMySQL.Migrating.RDSMySQL.Replica.Promote.CLI"></a>

若要將 Aurora 僅供讀取複本提升為獨立資料庫叢集，請使用 [https://docs.aws.amazon.com/cli/latest/reference/rds/promote-read-replica-db-cluster.html](https://docs.aws.amazon.com/cli/latest/reference/rds/promote-read-replica-db-cluster.html) AWS CLI 命令。

**Example**  
對於 Linux、macOS 或 Unix：  

```
aws rds promote-read-replica-db-cluster \
    --db-cluster-identifier myreadreplicacluster
```
在 Windows 中：  

```
aws rds promote-read-replica-db-cluster ^
    --db-cluster-identifier myreadreplicacluster
```