

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

# 將資料從 MySQL 資料庫快照遷移至 MariaDB 資料庫執行個體
<a name="USER_Migrate_MariaDB"></a>

您可以使用 AWS 管理主控台、AWS CLI 或 Amazon RDS API，將 RDS for MySQL 資料庫快照遷移至執行 MariaDB 的新資料庫執行個體。您必須使用從執行 MySQL 5.6 或 5.7 的 Amazon RDS 資料庫執行個體建立的資料庫快照。若要了解如何建立 RDS for MySQL 資料庫快照，請參閱[為 Amazon RDS 的單一可用區域資料庫執行個體建立資料庫快照](USER_CreateSnapshot.md)。

遷移快照不會影響從中擷取快照的原始資料庫執行個體。您可以先測試和驗證新資料庫執行個體，再將流量轉移到新資料庫執行個體來替代原始資料庫執行個體。

在從 MySQL 遷移至 MariaDB 之後，MariaDB 資料庫執行個體將與預設資料庫參數群組和選項群組相關聯。在還原資料庫快照之後，您可以使自訂資料庫參數群組與新的資料庫執行個體產生關聯。不過，MariaDB 參數群組具有一組不同的可設定系統變數。如需 MySQL 系統變數與 MariaDB 系統變數之間差異的相關資訊，請參閱 [MariaDB 與 MySQL 之間的系統變數差異](https://mariadb.com/kb/en/system-variable-differences-between-mariadb-and-mysql/)。若要了解資料庫參數群組，請參閱[Amazon RDS 的參數群組](USER_WorkingWithParamGroups.md)。若要了解選項群組，請參閱[使用選項群組](USER_WorkingWithOptionGroups.md)。

## 執行遷移
<a name="USER_Migrate_MariaDB.Migrating"></a>

您可以使用 AWS 管理主控台、AWS CLI 或 RDS API，將 RDS for MySQL 資料庫快照遷移至新的 MariaDB 資料庫執行個體。

### 主控台
<a name="USER_Migrate_MariaDB.CON"></a>

**將 MySQL 資料庫快照遷移至 MariaDB 資料庫執行個體**

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

1. 在導覽窗格中，選擇 **Snapshots** (快照)，然後選取您要遷移的 MySQL 資料庫快照。

1. 針對 **Actions** (動作)，選擇 **Migrate Snapshot** (遷移快照)。**Migrate Database (遷移資料庫)** 頁面隨即出現。

1. 針對 **Migrate to DB Engine (遷移至資料庫引擎)**，選擇 **mariadb**。

   Amazon RDS 會自動選取 **DB engine version (資料庫引擎版本)**。您無法變更資料庫引擎版本。  
![\[Amazon RDS 主控台中用來從 MySQL 遷移至 MariaDB 的遷移頁面。\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/UserGuide/images/MigrateMariaDB.png)

1. 在其餘區段，指定資料庫執行個體的設定。如需每項設定的相關資訊，請參閱 [資料庫執行個體的設定](USER_CreateDBInstance.Settings.md)。

1. 選擇 **Migrate (遷移)**。

### AWS CLI
<a name="USER_Migrate_MariaDB.CLI"></a>

若要將資料從 MySQL 資料庫快照遷移至 MariaDB 資料庫執行個體，請使用下列選項執行 AWS CLI [https://docs.aws.amazon.com/cli/latest/reference/rds/restore-db-instance-from-db-snapshot.html](https://docs.aws.amazon.com/cli/latest/reference/rds/restore-db-instance-from-db-snapshot.html) 命令：
+ --db-instance-identifier – 要從資料庫快照建立之資料庫執行個體的名稱。
+ --db-snapshot-identifier – 要從中還原之資料庫快照的識別碼。
+ --engine – 要用於新執行個體的資料庫引擎。

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

```
1. aws rds restore-db-instance-from-db-snapshot \
2.     --db-instance-identifier newmariadbinstance \
3.     --db-snapshot-identifier mysqlsnapshot \
4.     --engine mariadb
```
針對 Windows：  

```
1. aws rds restore-db-instance-from-db-snapshot ^
2.     --db-instance-identifier newmariadbinstance ^
3.     --db-snapshot-identifier mysqlsnapshot ^
4.     --engine mariadb
```

### API
<a name="USER_Migrate_MariaDB.API"></a>

若要將資料從 MySQL 資料庫快照遷移至 MariaDB 資料庫執行個體，請呼叫 Amazon RDS API 作業 [https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_RestoreDBInstanceFromDBSnapshot.html](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_RestoreDBInstanceFromDBSnapshot.html)。

## MariaDB 與 MySQL 之間的不相容性
<a name="USER_Migrate_MariaDB.Incompatibilities"></a>

MySQL 與 MariaDB 之間的不相容性包括下列情況：
+ 您無法將利用 MySQL 8.0 建立的資料庫快照遷移至 MariaDB。
+ 如果來源 MySQL 資料庫使用 SHA256 密碼雜湊，您必須重設 SHA256 雜湊的使用者密碼，才能連線到 MariaDB 資料庫。下列程式碼展示如何重設 SHA256 雜湊的密碼。

  ```
  SET old_passwords = 0;
  UPDATE mysql.user SET plugin = 'mysql_native_password',
  Password = PASSWORD('new_password')
  WHERE (User, Host) = ('master_user_name', %);
  FLUSH PRIVILEGES;
  ```
+ 如果您的 RDS 主要使用者帳戶使用 SHA-256 密碼雜湊，請確認使用 AWS 管理主控台、[https://docs.aws.amazon.com/cli/latest/reference/rds/modify-db-instance.html](https://docs.aws.amazon.com/cli/latest/reference/rds/modify-db-instance.html) AWS CLI 命令或 [ModifyDBInstance](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_ModifyDBInstance.html) RDS API 操作來重設密碼。如需修改資料庫執行個體的相關資訊，請參閱[修改 Amazon RDS 資料庫執行個體](Overview.DBInstance.Modifying.md)。
+ MariaDB 不支援 Memcached 外掛程式。不過，Memcached 外掛程式所使用的資料會儲存為 InnoDB 資料表。在遷移 MySQL 資料庫快照之後，您可以使用 SQL 來存取 Memcached 外掛程式所使用的資料。如需 innodb\$1memcache 資料庫的詳細資訊，請參閱 [ InnoDB memcached 外掛程式內部](https://dev.mysql.com/doc/refman/8.0/en/innodb-memcached-internals.html)。