AWS DMS 中 Full Load 的3 种 ”目标表准备模式“ 。
不执行任何操作:目标表中存在数据不会被更改,只会插入不一样的数据。
删除目标中的表:表会被删除,重建。
截断:表不会被删除。数据会被truncate。
原表结构及数据:
mysql> desc test_dms_1
-> ;
+-------+-----------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+-------------------+-----------------------------+
| id | int(11) | NO | PRI | NULL | |
| utime | timestamp | YES | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------+-----------+------+-----+-------------------+-----------------------------+
2 rows in set (0.03 sec)
mysql> select * from test_dms_1;
+----+---------------------+
| id | utime |
+----+---------------------+
| 1 | 2020-01-01 09:00:00 |
| 2 | 2020-01-01 09:00:00 |
+----+---------------------+
2 rows in set (0.03 sec)
测试(1): 同步任务中将 “目标表准备模式” 设置为 “截断”。同步前先创建目标表,再执行任务。
目标:
mysql> desc test_dms_1;
+-------+-----------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+-------------------+-----------------------------+
| id | int(11) | NO | PRI | NULL | |
| utime | timestamp | YES | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------+-----------+------+-----+-------------------+-----------------------------+
2 rows in set (0.04 sec)
mysql> select * from test_dms_1;
+----+---------------------+
| id | utime |
+----+---------------------+
| 1 | 2020-01-01 09:00:00 |
| 2 | 2020-01-01 09:00:00 |
+----+---------------------+
2 rows in set (0.03 sec)
源端插入数据:
mysql> insert into test_dms_1 values (3,'2020-02-01 01:00:00');
Query OK, 1 row affected (0.03 sec)
查询目标端:
mysql> select * from test_dms_1;
+----+---------------------+
| id | utime |
+----+---------------------+
| 1 | 2020-01-01 09:00:00 |
| 2 | 2020-01-01 09:00:00 |
| 3 | 2020-02-01 01:00:00 |
+----+---------------------+
3 rows in set (0.02 sec)
测试(2): 同步任务中将 “目标表准备模式” 设置为 “不执行任何操作”。 同步前先创建目标表中存在数据,再执行任务。如果原数据不一致,目标端数据也不会被更改。只会增加不一样的数据。
同步前源端:
更改源端数值,使源端与目标端不同。
mysql> update test_dms_1 set utime = '2020-03-01 03:00:00' where id = 2;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from test_dms_1;
+----+---------------------+
| id | utime |
+----+---------------------+
| 1 | 2020-01-01 09:00:00 |
| 2 | 2020-03-01 03:00:00 |
| 3 | 2020-02-01 01:00:00 |
| 4 | 2020-02-02 01:00:00 |
+----+---------------------+
4 rows in set (0.02 sec)
同步前目标端:
mysql> desc test_dms_1;
+-------+-----------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+-------------------+-----------------------------+
| id | int(11) | NO | PRI | NULL | |
| utime | timestamp | YES | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------+-----------+------+-----+-------------------+-----------------------------+
2 rows in set (0.04 sec)
mysql> select * from test_dms_1;
+----+---------------------+
| id | utime |
+----+---------------------+
| 1 | 2020-01-01 09:00:00 |
| 2 | 2020-01-01 09:00:00 |
| 3 | 2020-02-01 01:00:00 |
+----+---------------------+
3 rows in set (0.02 sec)
同步后目标端:
mysql> select * from test_dms_1;
+----+---------------------+
| id | utime |
+----+---------------------+
| 1 | 2020-01-01 09:00:00 |
| 2 | 2020-01-01 09:00:00 |
| 3 | 2020-02-01 01:00:00 |
| 4 | 2020-02-02 01:00:00 |
+----+---------------------+
4 rows in set (0.03 sec)
向源端插入数据
mysql> insert into test_dms_1 values (5,'2020-02-02 01:00:00');
Query OK, 1 row affected (0.02 sec)
目标端
mysql> select * from test_dms_1;
+----+---------------------+
| id | utime |
+----+---------------------+
| 1 | 2020-01-01 09:00:00 |
| 2 | 2020-01-01 09:00:00 |
| 3 | 2020-02-01 01:00:00 |
| 4 | 2020-02-02 01:00:00 |
| 5 | 2020-02-02 01:00:00 |
+----+---------------------+
5 rows in set (0.04 sec)
测试(3): 同步任务中将 “目标表准备模式” 设置为 “删除目标中的表”。 同步前先创建目标表中存在数据,再执行任务。
同步后目标端表改变:
mysql> desc test_dms_1;
+-------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| utime | timestamp | YES | | NULL | |
+-------+-----------+------+-----+---------+-------+
2 rows in set (0.02 sec)
mysql> select * from test_dms_1;
+----+---------------------+
| id | utime |
+----+---------------------+
| 1 | 2020-01-01 09:00:00 |
| 2 | 2020-01-01 09:00:00 |
| 3 | 2020-02-01 01:00:00 |
| 4 | 2020-02-02 01:00:00 |
| 5 | 2020-02-02 01:00:00 |
+----+---------------------+
5 rows in set (0.03 sec)
源端插入数据:
mysql> insert into test_dms_1 values (6,'2020-02-02 01:00:00');
Query OK, 1 row affected (0.04 sec)
查询目标端:
mysql> select * from test_dms_1;
+----+---------------------+
| id | utime |
+----+---------------------+
| 1 | 2020-01-01 09:00:00 |
| 2 | 2020-01-01 09:00:00 |
| 3 | 2020-02-01 01:00:00 |
| 4 | 2020-02-02 01:00:00 |
| 5 | 2020-02-02 01:00:00 |
| 6 | 2020-02-02 01:00:00 |
+----+---------------------+
6 rows in set (0.03 sec)