mysql主从复制(gtid模式)修改主库ip
环境:
OS:Centos 7
DB:mysql 5.7.29
基于GTID复制的主从环境,主库修改了ip后,修改从库同步信息(不需要指定master_log_file和master_log_pos)
1.停掉从库
stop slave;
2.查看从库状态
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.1.105
Master_User: repl
Master_Port: 13306
Connect_Retry: 60
Master_Log_File: binlog.000007
Read_Master_Log_Pos: 194
Relay_Log_File: relaylog-binlog.000017
Relay_Log_Pos: 401
Relay_Master_Log_File: binlog.000007
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB: information_schema,performance_schema,sys
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 194
Relay_Log_Space: 692
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: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 2003
Last_IO_Error: error reconnecting to master 'repl@192.168.1.105:13306' - retry-time: 60 retries: 9
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 9ecf61e2-eed1-11ed-a4b0-080027e81195
Master_Info_File: /opt/mysql57/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp: 230511 21:39:22
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 9ecf61e2-eed1-11ed-a4b0-080027e81195:1-257
Executed_Gtid_Set: 636915ca-ef98-11ed-a854-080027962264:1-836,
9ecf61e2-eed1-11ed-a4b0-080027e81195:1-257
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
ERROR:
No query specified
我这里Auto_Position: 0
3.尝试清理主库的已经同步过的binlog
主库执行:
mysql> purge binary logs to 'binlog.000002';
Query OK, 0 rows affected (0.06 sec)
4.修改ip地址
change master to master_host='192.168.1.104',
master_port=13306,
master_user='repl',
master_password='mysql';
5.启动
start slave;
6.查看
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Queueing master event to the relay log
Master_Host: 192.168.1.104
Master_User: repl
Master_Port: 13306
Connect_Retry: 60
Master_Log_File: binlog.000002 ##这里会重新同步主库的binlog,因为binlog.000001已经清理掉了,会从binlog.000002开始
Read_Master_Log_Pos: 34780157
Relay_Log_File: relaylog-binlog.000002
Relay_Log_Pos: 32643225
Relay_Master_Log_File: binlog.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB: information_schema,performance_schema,sys
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 32643058
Relay_Log_Space: 34780531
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: 57587
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: 1
Master_UUID: 9ecf61e2-eed1-11ed-a4b0-080027e81195
Master_Info_File: /opt/mysql57/data/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: 9ecf61e2-eed1-11ed-a4b0-080027e81195:80-95 ##这里从80开始接收,是因为1-79在binlog.000001,已经清理掉
Executed_Gtid_Set: 636915ca-ef98-11ed-a854-080027962264:1-836,
9ecf61e2-eed1-11ed-a4b0-080027e81195:1-257
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.06 sec)
ERROR:
No query specified