小規模データセットを MySQL から TiDB に移行する

このドキュメントでは、TiDB データ移行 (DM) を使用して、完全移行モードと増分レプリケーション モードで小規模データセットを MySQL から TiDB に移行する方法について説明します。このドキュメントの「小規模データセット」とは、1 TiB 未満のデータ サイズを意味します。

移行速度は、テーブル スキーマ内のインデックスの数、ハードウェア、ネットワーク環境などの複数の要因に応じて、30 GB/時間から 50 GB/時間まで変化します。

前提条件

ステップ1. データソースを作成する

まず、次のようにsource1.yamlファイルを作成します。

# The ID must be unique. source-id: "mysql-01" # Configures whether DM-worker uses the global transaction identifier (GTID) to pull binlogs. To enable GTID, the upstream MySQL must have enabled GTID. If the upstream MySQL has automatic source-replica switching, the GTID mode is required. enable-gtid: true from: host: "${host}" # For example: 172.16.10.81 user: "root" password: "${password}" # Plaintext password is supported but not recommended. It is recommended to use dmctl encrypt to encrypt the plaintext password before using the password. port: 3306

次に、次のコマンドを実行して、 tiup dmctl使用してデータ ソース構成を DM クラスターにロードします。

tiup dmctl --master-addr ${advertise-addr} operate-source create source1.yaml

上記のコマンドで使用されるパラメータは次のように記述されます。

パラメータ説明
--master-addrdmctlが接続するクラスター内の任意の DM マスター ノードの{advertise-addr}たとえば、172.16.10.71:8261。
operate-source createデータ ソースを DM クラスターにロードします。

ステップ2. 移行タスクを作成する

次のようにtask1.yamlファイルを作成します。

# Task name. Each of the multiple tasks running at the same time must have a unique name. name: "test" # Task mode. Options are: # full: only performs full data migration. # incremental: only performs binlog real-time replication. # all: full data migration + binlog real-time replication. task-mode: "all" # The configuration of the target TiDB database. target-database: host: "${host}" # For example: 172.16.10.83 port: 4000 user: "root" password: "${password}" # Plaintext password is supported but not recommended. It is recommended to use dmctl encrypt to encrypt the plaintext password before using the password. # The configuration of all MySQL instances of source database required for the current migration task. mysql-instances: - # The ID of an upstream instance or a replication group source-id: "mysql-01" # The names of the block list and allow list configuration of the schema name or table name that is to be migrated. These names are used to reference the global configuration of the block and allowlist. For the global configuration, refer to the `block-allow-list` configuration below. block-allow-list: "listA" # The global configuration of blocklist and allowlist. Each instance is referenced by a configuration item name. block-allow-list: listA: # name do-tables: # The allowlist of upstream tables that need to be migrated. - db-name: "test_db" # The schema name of the table to be migrated. tbl-name: "test_table" # The name of the table to be migrated.

上記は移行を実行するための最小限のタスク構成です。タスクに関するその他の構成項目については、 DMタスクの完全な構成ファイルの紹介を参照してください。

ステップ3. 移行タスクを開始する

エラーを回避するには、移行タスクを開始する前に、 check-taskコマンドを使用して、構成が DM 構成の要件を満たしているかどうかを確認することをお勧めします。

tiup dmctl --master-addr ${advertise-addr} check-task task.yaml

次のコマンドをtiup dmctlで実行して移行タスクを開始します。

tiup dmctl --master-addr ${advertise-addr} start-task task.yaml

上記のコマンドで使用されるパラメータは次のように記述されます。

パラメータ説明
--master-addrdmctlが接続されるクラスター内の任意の DM マスター ノードの{advertise-addr}例: 172.16.10.71:8261。
start-task移行タスクを開始する

タスクの起動に失敗した場合は、返された結果に従って設定を変更した後、 start-task task.yamlコマンドを実行してタスクを再起動できます。問題が発生した場合は、 エラーの処理FAQを参照してください。

ステップ4: 移行タスクのステータスを確認する

DM クラスターに進行中の移行タスクがあるかどうか、タスクのステータス、およびその他の情報を確認するには、 tiup dmctlを使用してquery-statusコマンドを実行します。

tiup dmctl --master-addr ${advertise-addr} query-status ${task-name}

結果の詳細な解釈についてはクエリステータスを参照してください。

ステップ5. タスクを監視してログを表示する(オプション)

移行タスクの履歴ステータスやその他の内部メトリックを表示するには、次の手順を実行します。

TiUPを使用して DM をデプロイするときに Prometheus、Alertmanager、および Grafana をデプロイした場合は、デプロイ中に指定した IP アドレスとポートを使用して Grafana にアクセスできます。その後、DM ダッシュボードを選択して、DM 関連の監視メトリックを表示できます。

  • DM マスターのログ ディレクトリ: DM マスター プロセス パラメータ--log-fileで指定されます。TiUPを使用して DM を展開した場合、ログ ディレクトリはデフォルトで/dm-deploy/dm-master-8261/log/になります。
  • DM-worker のログ ディレクトリ: DM-worker プロセス パラメータ--log-fileで指定されます。TiUPを使用して DM をデプロイした場合、ログ ディレクトリはデフォルトで/dm-deploy/dm-worker-8262/log/になります。

次は何ですか

このページは役に立ちましたか?

Playground
登録なしで TiDB の機能をワンストップでインタラクティブに体験できます。
製品
TiDB Dedicated
TiDB Serverless
TiDB
価格
PoC お問い合わせ
エコシステム
TiKV
TiFlash
OSS Insight
© 2024 PingCAP. All Rights Reserved.
Privacy Policy.