TiDB Data Migration (DM) is an integrated data replication task management platform that supports the full data migration and the incremental data migration from MySQL/MariaDB into TiDB. It can help to reduce the operations cost and simplify the troubleshooting process.
DM replicates data to TiDB in the form of SQL statements, so each version of DM is compatible with all versions of TiDB. In the production environment, it is recommended to use the latest released version of DM. To install DM, see DM download link.
The Data Migration tool includes three components: DM-master, DM-worker, and dmctl.
DM-master manages and schedules the operation of data replication tasks.
DM-worker executes specific data replication tasks.
After DM-worker is started, it automatically replicates the upstream binlog to the local configuration directory (the default replication directory is
<deploy_dir>/relay_log if DM is deployed using
DM-Ansible). For details about DM-worker, see DM-worker Introduction. For details about the relay log, see Relay Log.
dmctl is the command line tool used to control the DM cluster.
This section describes the data replication features provided by the Data Migration tool.
The schema and table routing feature means that DM can replicate a certain table of the upstream MySQL or MariaDB instance to the specified table in the downstream, which can be used to merge or replicate the sharding data.
The black and white lists filtering rule of the upstream database instance tables is similar to MySQL
replication-rules-table, which can be used to filter or only replicate all operations of some databases or some tables.
Binlog event filtering is a more fine-grained filtering rule than the black and white lists filtering rule. You can use statements like
TRUNCATE TABLE to specify the binlog events of
schema/table that you need to replicate or filter out.
DM supports merging the original sharded instances and tables into TiDB, but with some restrictions.
Before using the DM tool, note the following restrictions:
If there is a master-slave replication structure between the upstream MySQL/MariaDB servers, then choose the following version.
- 5.7.1 < MySQL version < 8.0
- MariaDB version >= 10.1.3
Data Migration prechecks the corresponding privileges and configuration automatically while starting the data replication task using dmctl.
Currently, TiDB is not compatible with all the DDL statements that MySQL supports. Because DM uses the TiDB parser to process DDL statements, it only supports the DDL syntax supported by the TiDB parser. For details, see MySQL Compatibility.
DM reports an error when it encounters an incompatible DDL statement. To solve this error, you need to manually handle it using dmctl, either skipping this DDL statement or replacing it with a specified DDL statement(s). For details, see Skip or replace abnormal SQL statements.
If conflict exists between sharded tables, solve the conflict by referring to handling conflicts of auto-increment primary key. Otherwise, data replication is not supported. Conflicting data can cover each other and cause data loss.
For other sharding restrictions, see Sharding DDL usage restrictions.
After DM-worker is restarted, the data replication task cannot be automatically restored. You need to manually run
start-task. For details, see Manage the Data Replication Task.
After DM-worker is restarted, the DDL lock replication cannot be automatically restored in some conditions. You need to manually handle it. For details, see Handle Sharding DDL Locks Manually.
Switching DM-worker connection to another MySQL instance
When DM-worker connects the upstream MySQL instance via a virtual IP (VIP), if you switch the VIP connection to another MySQL instance, DM might connect to the new and old MySQL instances at the same time in different connections. In this situation, the binlog replicated to DM is not consistent with other upstream status that DM receives, causing unpredictable anomalies and even data damage. To make necessary changes to DM manually, refer to Switch DM-worker connection via virtual IP.