- Docs Home
- About TiDB
- Quick Start
- Develop
- Overview
- Quick Start
- Build a TiDB Cluster in TiDB Cloud (Developer Tier)
- CRUD SQL in TiDB
- Build a Simple CRUD App with TiDB
- Example Applications
- Connect to TiDB
- Design Database Schema
- Write Data
- Read Data
- Transaction
- Optimize
- Troubleshoot
- Reference
- Cloud Native Development Environment
- Third-party Support
- Deploy
- Software and Hardware Requirements
- Environment Configuration Checklist
- Plan Cluster Topology
- Install and Start
- Verify Cluster Status
- Test Cluster Performance
- Migrate
- Overview
- Migration Tools
- Migration Scenarios
- Migrate from Aurora
- Migrate MySQL of Small Datasets
- Migrate MySQL of Large Datasets
- Migrate and Merge MySQL Shards of Small Datasets
- Migrate and Merge MySQL Shards of Large Datasets
- Migrate from CSV Files
- Migrate from SQL Files
- Migrate from One TiDB Cluster to Another TiDB Cluster
- Migrate from TiDB to MySQL-compatible Databases
- Advanced Migration
- Integrate
- Maintain
- Monitor and Alert
- Troubleshoot
- TiDB Troubleshooting Map
- Identify Slow Queries
- Analyze Slow Queries
- SQL Diagnostics
- Identify Expensive Queries Using Top SQL
- Identify Expensive Queries Using Logs
- Statement Summary Tables
- Troubleshoot Hotspot Issues
- Troubleshoot Increased Read and Write Latency
- Save and Restore the On-Site Information of a Cluster
- Troubleshoot Cluster Setup
- Troubleshoot High Disk I/O Usage
- Troubleshoot Lock Conflicts
- Troubleshoot TiFlash
- Troubleshoot Write Conflicts in Optimistic Transactions
- Troubleshoot Inconsistency Between Data and Indexes
- Performance Tuning
- Tuning Guide
- Configuration Tuning
- System Tuning
- Software Tuning
- SQL Tuning
- Overview
- Understanding the Query Execution Plan
- SQL Optimization Process
- Overview
- Logic Optimization
- Physical Optimization
- Prepare Execution Plan Cache
- Control Execution Plans
- Tutorials
- TiDB Tools
- Overview
- Use Cases
- Download
- TiUP
- Documentation Map
- Overview
- Terminology and Concepts
- Manage TiUP Components
- FAQ
- Troubleshooting Guide
- Command Reference
- Overview
- TiUP Commands
- TiUP Cluster Commands
- Overview
- tiup cluster audit
- tiup cluster check
- tiup cluster clean
- tiup cluster deploy
- tiup cluster destroy
- tiup cluster disable
- tiup cluster display
- tiup cluster edit-config
- tiup cluster enable
- tiup cluster help
- tiup cluster import
- tiup cluster list
- tiup cluster patch
- tiup cluster prune
- tiup cluster reload
- tiup cluster rename
- tiup cluster replay
- tiup cluster restart
- tiup cluster scale-in
- tiup cluster scale-out
- tiup cluster start
- tiup cluster stop
- tiup cluster template
- tiup cluster upgrade
- TiUP DM Commands
- Overview
- tiup dm audit
- tiup dm deploy
- tiup dm destroy
- tiup dm disable
- tiup dm display
- tiup dm edit-config
- tiup dm enable
- tiup dm help
- tiup dm import
- tiup dm list
- tiup dm patch
- tiup dm prune
- tiup dm reload
- tiup dm replay
- tiup dm restart
- tiup dm scale-in
- tiup dm scale-out
- tiup dm start
- tiup dm stop
- tiup dm template
- tiup dm upgrade
- TiDB Cluster Topology Reference
- DM Cluster Topology Reference
- Mirror Reference Guide
- TiUP Components
- PingCAP Clinic Diagnostic Service
- TiDB Operator
- Dumpling
- TiDB Lightning
- TiDB Data Migration
- About TiDB Data Migration
- Architecture
- Quick Start
- Deploy a DM cluster
- Tutorials
- Advanced Tutorials
- Maintain
- Cluster Upgrade
- Tools
- Performance Tuning
- Manage Data Sources
- Manage Tasks
- Export and Import Data Sources and Task Configurations of Clusters
- Handle Alerts
- Daily Check
- Reference
- Architecture
- Command Line
- Configuration Files
- OpenAPI
- Compatibility Catalog
- Secure
- Monitoring and Alerts
- Error Codes
- Glossary
- Example
- Troubleshoot
- Release Notes
- Backup & Restore (BR)
- TiDB Binlog
- TiCDC
- Dumpling
- sync-diff-inspector
- TiSpark
- Reference
- Cluster Architecture
- Key Monitoring Metrics
- Secure
- Privileges
- SQL
- SQL Language Structure and Syntax
- SQL Statements
ADD COLUMN
ADD INDEX
ADMIN
ADMIN CANCEL DDL
ADMIN CHECKSUM TABLE
ADMIN CHECK [TABLE|INDEX]
ADMIN SHOW DDL [JOBS|QUERIES]
ADMIN SHOW TELEMETRY
ALTER DATABASE
ALTER INDEX
ALTER INSTANCE
ALTER PLACEMENT POLICY
ALTER TABLE
ALTER TABLE COMPACT
ALTER USER
ANALYZE TABLE
BACKUP
BATCH
BEGIN
CHANGE COLUMN
COMMIT
CHANGE DRAINER
CHANGE PUMP
CREATE [GLOBAL|SESSION] BINDING
CREATE DATABASE
CREATE INDEX
CREATE PLACEMENT POLICY
CREATE ROLE
CREATE SEQUENCE
CREATE TABLE LIKE
CREATE TABLE
CREATE USER
CREATE VIEW
DEALLOCATE
DELETE
DESC
DESCRIBE
DO
DROP [GLOBAL|SESSION] BINDING
DROP COLUMN
DROP DATABASE
DROP INDEX
DROP PLACEMENT POLICY
DROP ROLE
DROP SEQUENCE
DROP STATS
DROP TABLE
DROP USER
DROP VIEW
EXECUTE
EXPLAIN ANALYZE
EXPLAIN
FLASHBACK TABLE
FLUSH PRIVILEGES
FLUSH STATUS
FLUSH TABLES
GRANT <privileges>
GRANT <role>
INSERT
KILL [TIDB]
LOAD DATA
LOAD STATS
MODIFY COLUMN
PREPARE
RECOVER TABLE
RENAME INDEX
RENAME TABLE
REPLACE
RESTORE
REVOKE <privileges>
REVOKE <role>
ROLLBACK
SELECT
SET DEFAULT ROLE
SET [NAMES|CHARACTER SET]
SET PASSWORD
SET ROLE
SET TRANSACTION
SET [GLOBAL|SESSION] <variable>
SHOW ANALYZE STATUS
SHOW [BACKUPS|RESTORES]
SHOW [GLOBAL|SESSION] BINDINGS
SHOW BUILTINS
SHOW CHARACTER SET
SHOW COLLATION
SHOW [FULL] COLUMNS FROM
SHOW CONFIG
SHOW CREATE PLACEMENT POLICY
SHOW CREATE SEQUENCE
SHOW CREATE TABLE
SHOW CREATE USER
SHOW DATABASES
SHOW DRAINER STATUS
SHOW ENGINES
SHOW ERRORS
SHOW [FULL] FIELDS FROM
SHOW GRANTS
SHOW INDEX [FROM|IN]
SHOW INDEXES [FROM|IN]
SHOW KEYS [FROM|IN]
SHOW MASTER STATUS
SHOW PLACEMENT
SHOW PLACEMENT FOR
SHOW PLACEMENT LABELS
SHOW PLUGINS
SHOW PRIVILEGES
SHOW [FULL] PROCESSSLIST
SHOW PROFILES
SHOW PUMP STATUS
SHOW SCHEMAS
SHOW STATS_HEALTHY
SHOW STATS_HISTOGRAMS
SHOW STATS_META
SHOW STATUS
SHOW TABLE NEXT_ROW_ID
SHOW TABLE REGIONS
SHOW TABLE STATUS
SHOW [FULL] TABLES
SHOW [GLOBAL|SESSION] VARIABLES
SHOW WARNINGS
SHUTDOWN
SPLIT REGION
START TRANSACTION
TABLE
TRACE
TRUNCATE
UPDATE
USE
WITH
- Data Types
- Functions and Operators
- Overview
- Type Conversion in Expression Evaluation
- Operators
- Control Flow Functions
- String Functions
- Numeric Functions and Operators
- Date and Time Functions
- Bit Functions and Operators
- Cast Functions and Operators
- Encryption and Compression Functions
- Locking Functions
- Information Functions
- JSON Functions
- Aggregate (GROUP BY) Functions
- Window Functions
- Miscellaneous Functions
- Precision Math
- Set Operations
- List of Expressions for Pushdown
- TiDB Specific Functions
- Clustered Indexes
- Constraints
- Generated Columns
- SQL Mode
- Table Attributes
- Transactions
- Garbage Collection (GC)
- Views
- Partitioning
- Temporary Tables
- Cached Tables
- Character Set and Collation
- Placement Rules in SQL
- System Tables
mysql
- INFORMATION_SCHEMA
- Overview
ANALYZE_STATUS
CLIENT_ERRORS_SUMMARY_BY_HOST
CLIENT_ERRORS_SUMMARY_BY_USER
CLIENT_ERRORS_SUMMARY_GLOBAL
CHARACTER_SETS
CLUSTER_CONFIG
CLUSTER_HARDWARE
CLUSTER_INFO
CLUSTER_LOAD
CLUSTER_LOG
CLUSTER_SYSTEMINFO
COLLATIONS
COLLATION_CHARACTER_SET_APPLICABILITY
COLUMNS
DATA_LOCK_WAITS
DDL_JOBS
DEADLOCKS
ENGINES
INSPECTION_RESULT
INSPECTION_RULES
INSPECTION_SUMMARY
KEY_COLUMN_USAGE
METRICS_SUMMARY
METRICS_TABLES
PARTITIONS
PLACEMENT_POLICIES
PROCESSLIST
REFERENTIAL_CONSTRAINTS
SCHEMATA
SEQUENCES
SESSION_VARIABLES
SLOW_QUERY
STATISTICS
TABLES
TABLE_CONSTRAINTS
TABLE_STORAGE_STATS
TIDB_HOT_REGIONS
TIDB_HOT_REGIONS_HISTORY
TIDB_INDEXES
TIDB_SERVERS_INFO
TIDB_TRX
TIFLASH_REPLICA
TIKV_REGION_PEERS
TIKV_REGION_STATUS
TIKV_STORE_STATUS
USER_PRIVILEGES
VIEWS
METRICS_SCHEMA
- UI
- TiDB Dashboard
- Overview
- Maintain
- Access
- Overview Page
- Cluster Info Page
- Top SQL Page
- Key Visualizer Page
- Metrics Relation Graph
- SQL Statements Analysis
- Slow Queries Page
- Cluster Diagnostics
- Search Logs Page
- Instance Profiling
- Session Management and Configuration
- FAQ
- CLI
- Command Line Flags
- Configuration File Parameters
- System Variables
- Storage Engines
- Telemetry
- Errors Codes
- Table Filter
- Schedule Replicas by Topology Labels
- FAQs
- Release Notes
- All Releases
- Release Timeline
- TiDB Versioning
- v6.1
- v6.0
- v5.4
- v5.3
- v5.2
- v5.1
- v5.0
- v4.0
- v3.1
- v3.0
- v2.1
- v2.0
- v1.0
- Glossary
Key Features
This document describes the data migration features provided by TiDB Data Migration (DM) and introduces appropriate parameter configurations.
For different DM versions, pay attention to the different match rules of schema or table names in the table routing, block & allow lists, and binlog event filter features:
- For DM v1.0.5 or later versions, all the above features support the wildcard match. For all versions of DM, note that there can be only one
*
in the wildcard expression, and*
must be placed at the end. - For DM versions earlier than v1.0.5, table routing and binlog event filter support the wildcard but do not support the
[...]
and[!...]
expressions. The block & allow lists only supports the regular expression.
It is recommended that you use the wildcard for matching in simple scenarios.
Table routing
The table routing feature enables DM to migrate a certain table of the upstream MySQL or MariaDB instance to the specified table in the downstream.
- Configuring multiple different routing rules for a single table is not supported.
- The match rule of schema needs to be configured separately, which is used to migrate
CREATE/DROP SCHEMA xx
, as shown inrule-2
of the parameter configuration.
Parameter configuration
routes:
rule-1:
schema-pattern: "test_*"
table-pattern: "t_*"
target-schema: "test"
target-table: "t"
rule-2:
schema-pattern: "test_*"
target-schema: "test"
Parameter explanation
DM migrates the upstream MySQL or MariaDB instance table that matches the schema-pattern
/table-pattern
rule provided by Table selector to the downstream target-schema
/target-table
.
Usage examples
This section shows the usage examples in different scenarios.
Merge sharded schemas and tables
Assuming in the scenario of sharded schemas and tables, you want to migrate the test_{1,2,3...}
.t_{1,2,3...}
tables in two upstream MySQL instances to the test
.t
table in the downstream TiDB instance.
To migrate the upstream instances to the downstream test
.t
, you must create the following routing rules:
rule-1
is used to migrate DML or DDL statements of the table that matchesschema-pattern: "test_*"
andtable-pattern: "t_*"
to the downstreamtest
.t
.rule-2
is used to migrate DDL statements of the schema that matchesschema-pattern: "test_*"
, such asCREATE/DROP SCHEMA xx
.
- If the downstream
schema: test
already exists and is not to be deleted, you can omitrule-2
. - If the downstream
schema: test
does not exist and onlyrule-1
is configured, then it reports theschema test doesn't exist
error during migration.
rule-1:
schema-pattern: "test_*"
table-pattern: "t_*"
target-schema: "test"
target-table: "t"
rule-2:
schema-pattern: "test_*"
target-schema: "test"
Merge sharded schemas
Assuming in the scenario of sharded schemas, you want to migrate the test_{1,2,3...}
.t_{1,2,3...}
tables in the two upstream MySQL instances to the test
.t_{1,2,3...}
tables in the downstream TiDB instance.
To migrate the upstream schemas to the downstream test
.t_[1,2,3]
, you only need to create one routing rule.
rule-1:
schema-pattern: "test_*"
target-schema: "test"
Incorrect table routing
Assuming that the following two routing rules are configured and test_1_bak
.t_1_bak
matches both rule-1
and rule-2
, an error is reported because the table routing configuration violates the number limitation.
rule-1:
schema-pattern: "test_*"
table-pattern: "t_*"
target-schema: "test"
target-table: "t"
rule-2:
schema-pattern: "test_1_bak"
table-pattern: "t_1_bak"
target-schema: "test"
target-table: "t_bak"
Block and allow table lists
The block and allow lists filtering rule of the upstream database instance tables is similar to MySQL replication-rules-db/tables, which can be used to filter or only migrate all operations of some databases or some tables.
Parameter configuration
block-allow-list: # Use black-white-list if the DM version is earlier than or equal to v2.0.0-beta.2.
rule-1:
do-dbs: ["test*"] # Starting with characters other than "~" indicates that it is a wildcard;
# v1.0.5 or later versions support the regular expression rules.
do-tables:
- db-name: "test[123]" # Matches test1, test2, and test3.
tbl-name: "t[1-5]" # Matches t1, t2, t3, t4, and t5.
- db-name: "test"
tbl-name: "t"
rule-2:
do-dbs: ["~^test.*"] # Starting with "~" indicates that it is a regular expression.
ignore-dbs: ["mysql"]
do-tables:
- db-name: "~^test.*"
tbl-name: "~^t.*"
- db-name: "test"
tbl-name: "t"
ignore-tables:
- db-name: "test"
tbl-name: "log"
Parameter explanation
do-dbs
: allow lists of the schemas to be migrated, similar toreplicate-do-db
in MySQLignore-dbs
: block lists of the schemas to be migrated, similar toreplicate-ignore-db
in MySQLdo-tables
: allow lists of the tables to be migrated, similar toreplicate-do-table
in MySQL. Bothdb-name
andtbl-name
must be specifiedignore-tables
: block lists of the tables to be migrated, similar toreplicate-ignore-table
in MySQL. Bothdb-name
andtbl-name
must be specified
If a value of the above parameters starts with the ~
character, the subsequent characters of this value are treated as a regular expression. You can use this parameter to match schema or table names.
Filtering process
The filtering rules corresponding to do-dbs
and ignore-dbs
are similar to the Evaluation of Database-Level Replication and Binary Logging Options in MySQL. The filtering rules corresponding to do-tables
and ignore-tables
are similar to the Evaluation of Table-Level Replication Options in MySQL.
In DM and in MySQL, the allow and block lists filtering rules are different in the following ways:
- In MySQL,
replicate-wild-do-table
andreplicate-wild-ignore-table
support wildcard characters. In DM, some parameter values directly supports regular expressions that start with the~
character. - DM currently only supports binlogs in the
ROW
format, and does not support those in theSTATEMENT
orMIXED
format. Therefore, the filtering rules in DM correspond to those in theROW
format in MySQL. - MySQL determines a DDL statement only by the database name explicitly specified in the
USE
section of the statement. DM determines a statement first based on the database name section in the DDL statement. If the DDL statement does not contain such a section, DM determines the statement by theUSE
section. Suppose that the SQL statement to be determined isUSE test_db_2; CREATE TABLE test_db_1.test_table (c1 INT PRIMARY KEY)
; thatreplicate-do-db=test_db_1
is configured in MySQL anddo-dbs: ["test_db_1"]
is configured in DM. Then this rule only applies to DM and not to MySQL.
The filtering process is as follows:
Filter at the schema level:
If
do-dbs
is not empty, judge whether a matched schema exists indo-dbs
.- If yes, continue to filter at the table level.
- If not, filter
test
.t
.
If
do-dbs
is empty andignore-dbs
is not empty, judge whether a matched schema exits inignore-dbs
.- If yes, filter
test
.t
. - If not, continue to filter at the table level.
- If yes, filter
If both
do-dbs
andignore-dbs
are empty, continue to filter at the table level.
Filter at the table level:
If
do-tables
is not empty, judge whether a matched table exists indo-tables
.- If yes, migrate
test
.t
. - If not, filter
test
.t
.
- If yes, migrate
If
ignore-tables
is not empty, judge whether a matched table exists inignore-tables
.- If yes, filter
test
.t
. - If not, migrate
test
.t
.
- If yes, filter
If both
do-tables
andignore-tables
are empty, migratetest
.t
.
To judge whether the schema test
should be filtered, you only need to filter at the schema level.
Usage example
Assume that the upstream MySQL instances include the following tables:
`logs`.`messages_2016`
`logs`.`messages_2017`
`logs`.`messages_2018`
`forum`.`users`
`forum`.`messages`
`forum_backup_2016`.`messages`
`forum_backup_2017`.`messages`
`forum_backup_2018`.`messages`
The configuration is as follows:
block-allow-list: # Use black-white-list if the DM version is earlier than or equal to v2.0.0-beta.2.
bw-rule:
do-dbs: ["forum_backup_2018", "forum"]
ignore-dbs: ["~^forum_backup_"]
do-tables:
- db-name: "logs"
tbl-name: "~_2018$"
- db-name: "~^forum.*"
tbl-name: "messages"
ignore-tables:
- db-name: "~.*"
tbl-name: "^messages.*"
After using the bw-rule
rule:
Table | Whether to filter | Why filter |
---|---|---|
logs .messages_2016 | Yes | The schema logs fails to match any do-dbs . |
logs .messages_2017 | Yes | The schema logs fails to match any do-dbs . |
logs .messages_2018 | Yes | The schema logs fails to match any do-dbs . |
forum_backup_2016 .messages | Yes | The schema forum_backup_2016 fails to match any do-dbs . |
forum_backup_2017 .messages | Yes | The schema forum_backup_2017 fails to match any do-dbs . |
forum .users | Yes | 1. The schema forum matches do-dbs and continues to filter at the table level.2. The schema and table fail to match any of do-tables and ignore-tables and do-tables is not empty. |
forum .messages | No | 1. The schema forum matches do-dbs and continues to filter at the table level.2. The table messages is in the db-name: "~^forum.*",tbl-name: "messages" of do-tables . |
forum_backup_2018 .messages | No | 1. The schema forum_backup_2018 matches do-dbs and continues to filter at the table level.2. The schema and table match the db-name: "~^forum.*",tbl-name: "messages" of do-tables . |
Binlog event filter
Binlog event filter is a more fine-grained filtering rule than the block and allow lists filtering rule. You can use statements like INSERT
or TRUNCATE TABLE
to specify the binlog events of schema/table
that you need to migrate or filter out.
- If the same table matches multiple rules, these rules are applied in order and the block list has priority over the allow list. This means if both the
Ignore
andDo
rules are applied to a table, theIgnore
rule takes effect. - Starting from DM v2.0.2, you can configure binlog event filters in the source configuration file. For details, see Upstream Database Configuration File.
Parameter configuration
filters:
rule-1:
schema-pattern: "test_*"
table-pattern: "t_*"
events: ["truncate table", "drop table"]
sql-pattern: ["^DROP\\s+PROCEDURE", "^CREATE\\s+PROCEDURE"]
action: Ignore
Parameter explanation
schema-pattern
/table-pattern
: the binlog events or DDL SQL statements of upstream MySQL or MariaDB instance tables that matchschema-pattern
/table-pattern
are filtered by the rules below.events
: the binlog event array. You can only select one or moreEvent
s from the following table:Events Type Description all
Includes all the events below all dml
Includes all DML events below all ddl
Includes all DDL events below none
Includes none of the events below none ddl
Includes none of the DDL events below none dml
Includes none of the DML events below insert
DML The INSERT
DML eventupdate
DML The UPDATE
DML eventdelete
DML The DELETE
DML eventcreate database
DDL The CREATE DATABASE
DDL eventdrop database
DDL The DROP DATABASE
DDL eventcreate table
DDL The CREATE TABLE
DDL eventcreate index
DDL The CREATE INDEX
DDL eventdrop table
DDL The DROP TABLE
DDL eventtruncate table
DDL The TRUNCATE TABLE
DDL eventrename table
DDL The RENAME TABLE
DDL eventdrop index
DDL The DROP INDEX
DDL eventalter table
DDL The ALTER TABLE
DDL eventsql-pattern
: it is used to filter specified DDL SQL statements. The matching rule supports using a regular expression. For example,"^DROP\\s+PROCEDURE"
.action
: the string (Do
/Ignore
). Based on the following rules, it judges whether to filter. If either of the two rules is satisfied, the binlog is filtered; otherwise, the binlog is not filtered.Do
: the allow list. The binlog is filtered in either of the following two conditions:- The type of the event is not in the
event
list of the rule. - The SQL statement of the event cannot be matched by
sql-pattern
of the rule.
- The type of the event is not in the
Ignore
: the block list. The binlog is filtered in either of the following two conditions:- The type of the event is in the
event
list of the rule. - The SQL statement of the event can be matched by
sql-pattern
of the rule.
- The type of the event is in the
Usage examples
This section shows the usage examples in the scenario of sharding (sharded schemas and tables).
Filter all sharding deletion operations
To filter out all deletion operations, configure the following two filtering rules:
filter-table-rule
filters out thetruncate table
,drop table
anddelete statement
operations of all tables that match thetest_*
.t_*
pattern.filter-schema-rule
filters out thedrop database
operation of all schemas that match thetest_*
pattern.
filters:
filter-table-rule:
schema-pattern: "test_*"
table-pattern: "t_*"
events: ["truncate table", "drop table", "delete"]
action: Ignore
filter-schema-rule:
schema-pattern: "test_*"
events: ["drop database"]
action: Ignore
Only migrate sharding DML statements
To only migrate sharding DML statements, configure the following two filtering rules:
do-table-rule
only migrates thecreate table
,insert
,update
anddelete
statements of all tables that match thetest_*
.t_*
pattern.do-schema-rule
only migrates thecreate database
statement of all schemas that match thetest_*
pattern.
The reason why the create database/table
statement is migrated is that you can migrate DML statements only after the schema and table are created.
filters:
do-table-rule:
schema-pattern: "test_*"
table-pattern: "t_*"
events: ["create table", "all dml"]
action: Do
do-schema-rule:
schema-pattern: "test_*"
events: ["create database"]
action: Do
Filter out the SQL statements that TiDB does not support
To filter out the PROCEDURE
statements that TiDB does not support, configure the following filter-procedure-rule
:
filters:
filter-procedure-rule:
schema-pattern: "test_*"
table-pattern: "t_*"
sql-pattern: ["^DROP\\s+PROCEDURE", "^CREATE\\s+PROCEDURE"]
action: Ignore
filter-procedure-rule
filters out the ^CREATE\\s+PROCEDURE
and ^DROP\\s+PROCEDURE
statements of all tables that match the test_*
.t_*
pattern.
Filter out the SQL statements that the TiDB parser does not support
For the SQL statements that the TiDB parser does not support, DM cannot parse them and get the schema
/table
information. So you must use the global filtering rule: schema-pattern: "*"
.
To avoid filtering out data that need to be migrated, you must configure the global filtering rule as strictly as possible.
To filter out the PARTITION
statements that the TiDB parser (of some version) does not support, configure the following filtering rule:
filters:
filter-partition-rule:
schema-pattern: "*"
sql-pattern: ["ALTER\\s+TABLE[\\s\\S]*ADD\\s+PARTITION", "ALTER\\s+TABLE[\\s\\S]*DROP\\s+PARTITION"]
action: Ignore
Online DDL tools
In the MySQL ecosystem, tools such as gh-ost and pt-osc are widely used. DM provides supports for these tools to avoid migrating unnecessary intermediate data.
Restrictions
- DM only supports gh-ost and pt-osc.
- When
online-ddl
is enabled, the checkpoint corresponding to incremental replication should not be in the process of online DDL execution. For example, if an upstream online DDL operation starts atposition-A
and ends atposition-B
of the binlog, the starting point of incremental replication should be earlier thanposition-A
or later thanposition-B
; otherwise, an error occurs. For details, refer to FAQ.
Parameter configuration
- v2.0.5 and later
- earlier than v2.0.5
In v2.0.5 and later versions, you need to use the online-ddl
configuration item in the task
configuration file.
- If the upstream MySQL/MariaDB (at the same time) uses the gh-ost or pt-osc tool, set
online-ddl
totrue
in the task configuration file:
online-ddl: true
Since v2.0.5, online-ddl-scheme
has been deprecated, so you need to use online-ddl
instead of online-ddl-scheme
. That means that setting online-ddl: true
overwrites online-ddl-scheme
, and setting online-ddl-scheme: "pt"
or online-ddl-scheme: "gh-ost"
is converted to online-ddl: true
.
Before v2.0.5 (not including v2.0.5), you need to use the online-ddl-scheme
configuration item in the task
configuration file.
- If the upstream MySQL/MariaDB uses the gh-ost tool, set it in the task configuration file:
online-ddl-scheme: "gh-ost"
- If the upstream MySQL/MariaDB uses the pt tool, set it in the task configuration file:
online-ddl-scheme: "pt"
Shard merge
DM supports merging the DML and DDL data in the upstream MySQL/MariaDB sharded tables and migrating the merged data to the downstream TiDB tables.
Restrictions
Currently, the shard merge feature is supported only in limited scenarios. For details, refer to Sharding DDL usage Restrictions in the pessimistic mode and Sharding DDL usage Restrictions in the optimistic mode.
Parameter configuration
Set shard-mode
to pessimistic
in the task configuration file:
shard-mode: "pessimistic" # The shard merge mode. Optional modes are ""/"pessimistic"/"optimistic". The "" mode is used by default which means sharding DDL merge is disabled. If the task is a shard merge task, set it to the "pessimistic" mode. After getting a deep understanding of the principles and restrictions of the "optimistic" mode, you can set it to the "optimistic" mode.
Handle sharding DDL locks manually
In some abnormal scenarios, you need to handle sharding DDL Locks manually.