原生mysql-到noshard(增量) mydumper myloader
增量在前一章节的全量基础上实现的。
创建增量(用超级权限,在主库是执行) #增量同步只适用于 原生mysql 到 tdsql noshard
a.配置主从
cd /data/tdsql_run/4002/percona-5.7.17/install ./jmysql.sh 4002 >>change master to master_host='10.85.10.55',master_port=3306, master_user='root',master_password='root',master_log_file='binlog.000001', master_log_pos=154,MASTER_AUTO_POSITION = 0 for channel 'migrateconnection' ; 自动开启了进程
b.配置过滤掉sys库
配置后,自动开启了进程 , 需要先停止才能更改过小虑。 但是我这里停了多次 ,才更改成功
mysql> stop slave for Channel 'migrateconnection'
mysql> STOP SLAVE ;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> show warnings ;
+-------+------+----------------------------------------------------------------------------+
| Level | Code | Message |
+-------+------+----------------------------------------------------------------------------+
| Note | 3084 | Replication thread(s) for channel 'migrateconnection' are already stopped. |
+-------+------+----------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> CHANGE REPLICATION FILTER REPLICATE_WILD_IGNORE_TABLE = ('mysql.%%') ;
Query OK, 0 rows affected (0.00 sec)
c.启动进程查持状态
#start slave for Channel 'migrateconnection' start slave 等了一会儿 IO 进程才起来 查看状态 >>show slave status\G 或show slave status for Channel 'migrateconnection' \G #STOP SLAVE IO_THREAD #STOP SLAVE SQL_THREAD #stop slave for Channel 'migrateconnection' #START SLAVE IO_THREAD #START SLAVESQL_THREAD #start slave for Channel 'migrateconnection'
d.问题处理:
1.主库没有按主从配置binlog ,gtid ,导致未同步
2.主库没有开启自动提交 autocommit ,导致测试数据没同步
3.未同步分析
a.主库进行事务操作发,检查事务号是否有变更
mysql> show master status\G
*************************** 1. row ***************************
File: binlog.000004
Position: 954 <---------- 事务备提交后,检查是否有改变
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: 2884544a-e20f-11ea-b50e-000c2956b241:1-3 <----------
1 row in set (0.00 sec)
b.从库检查当前SQL进程,IO进程,同时检查事务是否有变更
mysql> show slave status for Channel 'migrateconnection' \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.85.10.55
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000004
Read_Master_Log_Pos: 1264 #主库Log_Pos
Relay_Log_File: relay-migrateconnection.000003
Relay_Log_Pos: 357
Relay_Master_Log_File: binlog.000004
Slave_IO_Running: Yes # <----- 进程状态
Slave_SQL_Running: Yes # <----- 进程状态
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table: mysql.%% #过滤忽略同步的的表
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1264
Relay_Log_Space: 1837
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 513306
Master_UUID: 2884544a-e20f-11ea-b50e-000c2956b241
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 2884544a-e20f-11ea-b50e-000c2956b241:1-4 #已发现的事务id
Executed_Gtid_Set: 21f2d026-3946-11eb-829e-000c29eab121:1-16662, #从库同步执行的事务id
2884544a-e20f-11ea-b50e-000c2956b241:1-4,
6e9f519d-3946-11eb-8d07-000c2965c4bd:1-72224
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name: migrateconnection
Master_TLS_Version:
1 row in set (0.00 sec)
注意事项:
1. 增量同步 只能在 源生mysql 到 tdsql noshard 间进行 2.tdsql noshard 到 tdsql noshard 用多源同步 或 DCN 同步补充:
#检查主备数据一致性:
使用pt-table-checksum工具来进行校验。
方法:https://cloud.tencent.com/developer/article/1177904
风险:可能会影响主机。
#断开增量同步
>>stop slave migrateconnection
>>show slave status\G;//查看主备关系是否断开。
关于增量数据同步:
1.利用MySQL主备同步来获取增量数据
2.先获取镜像点,新建的主备关系将从该镜像点开始同步
3.Mydumper会产生一个metadata文件,其中记录了镜像点的信息。
注意:
1. 迁移时需要注意源实例的版本,原则上只支持低版本向高版本迁移。
2. TDSQL不支持myisam引擎表的创建,需要在源端将引擎改为innodb
3. 在创建主备同步关系时,需要显示指定channel名。