# DM 的使用 - Table routings

__*DM 使用*__
__*Table routings*__

```
routes: 
 route-rule-1:
    schema-pattern: "test_*"
    table-pattern: "t_*"
    target-schema: "test"
    target-table: "t"
  route-rule-2:
    schema-pattern: "test_*"
    target-schema: "test"
```
-------------------------------------------------------------
Table routing 提供将上游 MySQL/MariaDB 实例的某些表迁移到下游指定表的功能。
注意
不支持对同一个表设置多个不同的路由规则。
Schema 的匹配规则需要单独设置,用来迁移 CREATE/DROP SCHEMA xx,例如下面参数配置中的 rule-2。

参数解释
将根据 schema-pattern/table-pattern 匹配上该规则的上游 MySQL/MariaDB 实例的表迁移到下游的 target-schema/target-table。

分库分表合并
假设存在分库分表场景,需要将上游两个 MySQL 实例的表 test_{1,2,3...}.t_{1,2,3...} 迁移到下游 TiDB 的一张表 test.t。
为了迁移到下游实例的表 test.t,需要创建以下 table routing 规则:
rule-1 用来迁移匹配上 schema-pattern: "test_*" 和 table-pattern: "t_*" 的表的 DML/DDL 语句到下游的 test.t。
rule-2 用来迁移匹配上 schema-pattern: "test_*" 的库的 DDL 语句,例如 CREATE/DROP SCHEMA xx。

注意
如果下游 TiDB schema: test 已经存在,并且不会被删除,则可以省略 rule-2。
如果下游 TiDB schema: test 不存在,只设置了 rule_1,则迁移会报错 schema test doesn't exist。