1、备份主库
mysqldump -S /tmp/mysql_5000.sock --single-transaction --events --triggers --routines --master-data=2 --set-gtid-purged=off -B db1 db2 db3 db4 > bak_0219.sql
2、恢复数据到从库
mysql -S /tmp/mysql_5001.sock < bak_0219.sql
3、查看binlog位置
head -25 bak_0219.sql
显示如下
#CHANGE MASTER TO MASTER_LOG_FILE='binlog.001404', MASTER_LOG_POS=552304092;
4、创建主从复制:
mysql -S /tmp/mysql_5001.sock
CHANGE MASTER TO master_host='10.xxxx',master_port=5000,master_user='repl',master_password='xxxxx',MASTER_LOG_FILE='binlog.001404', MASTER_LOG_POS=552304092;
start slave;
show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: 10.xxx
Master_User: repl
Master_Port: 5000
Connect_Retry: 60
Master_Log_File: binlog.001404
Read_Master_Log_Pos: 651038715
Relay_Log_File: relay.000002
Relay_Log_Pos: 2715
Relay_Master_Log_File: binlog.001404
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table: db1.%,db2.%,db3.%,db4.%
Replicate_Wild_Ignore_Table:
Last_Errno: 1062
Last_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 2 failed executing transaction '1032978c-7f39-11e8-994a-fa8df5b38500:251059134' at source log binlog.001404, end_log_pos 552315580. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
Skip_Counter: 0
mysql> select * from performance_schema.replication_applier_status_by_worker;
Worker 2 failed executing transaction '1032978c-7f39-11e8-994a-fa8df5b38500:251059134' at source log binlog.001404, end_log_pos 552315580; Could not execute Write_rows event on table qlw_nxin_com.st_ruappsrelationship; Duplicate entry '2402191318160000109' for key 'st_ruappsrelationship.PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's source log binlog.001404, end_log_pos 552315580 | 2024-02-19 17:43:09.052577
墨值悬赏

评论
