1、主从基于POSITION号复制
现有需求,主库修改端口,从库需做什么操作
原主库端口由3307修改为3307
mysql> select @@port;
+--------+
| @@port |
+--------+
| 3307 |
+--------+
1 row in set (0.00 sec)
从库对应操作
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
mysql> change master to master_port=3307;
Query OK, 0 rows affected (0.02 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.0.100
Master_User: repl
Master_Port: 3307
Connect_Retry: 60
Master_Log_File: mysql-bin.000017
Read_Master_Log_Pos: 274
Relay_Log_File: db02-relay-bin.000002
Relay_Log_Pos: 367
Relay_Master_Log_File: mysql-bin.000017
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:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 274
Relay_Log_Space: 573
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: 100
Master_UUID: 0706ef47-886c-11eb-a9f0-000c29aec9e2
Master_Info_File: /data/mysql/data/master.info
SQL_Delay: 60
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:
Executed_Gtid_Set: 1518e04e-8638-11eb-a908-000c29aec9e2:1-24,
8c88da03-86be-11eb-ac3c-000c29aec9e2:1-10,
93f12623-86ce-11eb-9689-000c29aec9e2:1-67,
979a98c9-86ce-11eb-96b5-000c29eb57ff:1
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
ERROR:
No query specified
2、主从基于POSITIO号复制
如果主从之间并没有开启GTID,是基于position号复制的,那么直接change端口就不行了。
- 方法1
当我们的主库修改完端口,是需要重启的,当我们重启后,会生成一个新的日志,
我们可以通过从库查看下当前是否接收日志有延迟。
从库查看接收日志
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.0.100
Master_User: repl
Master_Port: 3308
Connect_Retry: 60
Master_Log_File: mysql-bin.000022
Read_Master_Log_Pos: 314
主库查看当前日志
mysql> show master status\G;
*************************** 1. row ***************************
File: mysql-bin.000022
Position: 314
此时说明主从日志传输之间没有延迟,日志是22
当我们重启主库之后,会新生成一个binlog日志23
[root@db01 binlog]# ll
total 792
-rw-r----- 1 mysql mysql 177 Mar 16 17:00 mysql-bin.000001
-rw-r----- 1 mysql mysql 1051 Mar 16 17:10 mysql-bin.000002
-rw-r----- 1 mysql mysql 177 Mar 16 17:14 mysql-bin.000003
-rw-r----- 1 mysql mysql 201 Mar 16 17:35 mysql-bin.000004
-rw-r----- 1 mysql mysql 201 Mar 16 17:36 mysql-bin.000005
-rw-r----- 1 mysql mysql 201 Mar 16 17:36 mysql-bin.000006
-rw-r----- 1 mysql mysql 5447 Mar 17 09:14 mysql-bin.000007
-rw-r----- 1 mysql mysql 217 Mar 17 09:17 mysql-bin.000008
-rw-r----- 1 mysql mysql 2438 Mar 17 11:04 mysql-bin.000009
-rw-r----- 1 mysql mysql 257 Mar 17 11:14 mysql-bin.000010
-rw-r----- 1 mysql mysql 257 Mar 17 11:12 mysql-bin.000011
-rw-r----- 1 mysql mysql 257 Mar 17 11:12 mysql-bin.000012
-rw-r----- 1 mysql mysql 2969 Mar 18 10:09 mysql-bin.000013
-rw-r----- 1 mysql mysql 27895 Mar 19 12:32 mysql-bin.000014
-rw-r----- 1 mysql mysql 297 Mar 19 12:31 mysql-bin.000015
-rw-r----- 1 mysql mysql 297 Mar 19 13:57 mysql-bin.000016
-rw-r----- 1 mysql mysql 691048 Mar 19 14:22 mysql-bin.000017
-rw-r----- 1 mysql mysql 337 Mar 19 16:29 mysql-bin.000018
-rw-r----- 1 mysql mysql 337 Mar 19 16:36 mysql-bin.000019
-rw-r----- 1 mysql mysql 337 Mar 19 16:38 mysql-bin.000020
-rw-r----- 1 mysql mysql 337 Mar 19 16:42 mysql-bin.000021
-rw-r----- 1 mysql mysql 875 Mar 19 16:53 mysql-bin.000022
-rw-r----- 1 mysql mysql 660 Mar 19 16:42 mysql-bin.index
[root@db01 binlog]# /etc/init.d/mysqld restart
Shutting down MySQL............ SUCCESS!
Starting MySQL.. SUCCESS!
[root@db01 binlog]# ll
total 796
-rw-r----- 1 mysql mysql 177 Mar 16 17:00 mysql-bin.000001
-rw-r----- 1 mysql mysql 1051 Mar 16 17:10 mysql-bin.000002
-rw-r----- 1 mysql mysql 177 Mar 16 17:14 mysql-bin.000003
-rw-r----- 1 mysql mysql 201 Mar 16 17:35 mysql-bin.000004
-rw-r----- 1 mysql mysql 201 Mar 16 17:36 mysql-bin.000005
-rw-r----- 1 mysql mysql 201 Mar 16 17:36 mysql-bin.000006
-rw-r----- 1 mysql mysql 5447 Mar 17 09:14 mysql-bin.000007
-rw-r----- 1 mysql mysql 217 Mar 17 09:17 mysql-bin.000008
-rw-r----- 1 mysql mysql 2438 Mar 17 11:04 mysql-bin.000009
-rw-r----- 1 mysql mysql 257 Mar 17 11:14 mysql-bin.000010
-rw-r----- 1 mysql mysql 257 Mar 17 11:12 mysql-bin.000011
-rw-r----- 1 mysql mysql 257 Mar 17 11:12 mysql-bin.000012
-rw-r----- 1 mysql mysql 2969 Mar 18 10:09 mysql-bin.000013
-rw-r----- 1 mysql mysql 27895 Mar 19 12:32 mysql-bin.000014
-rw-r----- 1 mysql mysql 297 Mar 19 12:31 mysql-bin.000015
-rw-r----- 1 mysql mysql 297 Mar 19 13:57 mysql-bin.000016
-rw-r----- 1 mysql mysql 691048 Mar 19 14:22 mysql-bin.000017
-rw-r----- 1 mysql mysql 337 Mar 19 16:29 mysql-bin.000018
-rw-r----- 1 mysql mysql 337 Mar 19 16:36 mysql-bin.000019
-rw-r----- 1 mysql mysql 337 Mar 19 16:38 mysql-bin.000020
-rw-r----- 1 mysql mysql 337 Mar 19 16:42 mysql-bin.000021
-rw-r----- 1 mysql mysql 898 Mar 19 16:56 mysql-bin.000022
-rw-r----- 1 mysql mysql 314 Mar 19 16:56 mysql-bin.000023
-rw-r----- 1 mysql mysql 690 Mar 19 16:56 mysql-bin.index
主库修改完端口重启后,从库需要重新指定主从信息,此时应该指定为新日志,position号为0的位置点信息即可。
mysql> CHANGE MASTER TO
-> MASTER_HOST='10.0.0.100',
-> MASTER_USER='repl',
-> MASTER_PASSWORD='123',
-> MASTER_PORT=3308,
-> MASTER_LOG_FILE='mysql-bin.000023',
-> MASTER_LOG_POS=0,
-> MASTER_CONNECT_RETRY=10;
Query OK, 0 rows affected, 2 warnings (0.02 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.0.100
Master_User: repl
Master_Port: 3308
Connect_Retry: 10
Master_Log_File: mysql-bin.000023
Read_Master_Log_Pos: 314
Relay_Log_File: db02-relay-bin.000002
Relay_Log_Pos: 367
Relay_Master_Log_File: mysql-bin.000023
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:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 314
Relay_Log_Space: 573
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: 100
Master_UUID: 0706ef47-886c-11eb-a9f0-000c29aec9e2
Master_Info_File: /data/mysql/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:
Executed_Gtid_Set: 0706ef47-886c-11eb-a9f0-000c29aec9e2:1-16,
1518e04e-8638-11eb-a908-000c29aec9e2:1-24,
8c88da03-86be-11eb-ac3c-000c29aec9e2:1-10,
93f12623-86ce-11eb-9689-000c29aec9e2:1-67
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
ERROR:
No query specified