1.mysql8复制报错。
Last_IO_Error: Source command COM_REGISTER_REPLICA failed:
Access denied for user 'repl'@'%' (using password: YES) (Errno: 1045)
2.mysql8的创建复制用户需要指定IP地址。
drop user repl@'%';
create user 'repl'@'10.1.1.1' identified by 'repl4slave';
grant replication client,replication slave on *.* to 'repl'@'10.1.1.1';
--或者:UPDATE mysql.user SET Repl_slave_priv='Y' WHERE User='repl';
--使用mysql5.7的密码策略的用户创建方法。
create user 'repl'@'10.1.1.1' identified with mysql_native_password by 'repl4slave';
grant replication client,replication slave on *.* to 'repl'@'10.1.1.1';
--3.查看主库的GTID位置。
mysql> SELECT @@GLOBAL.GTID_EXECUTED;
+-------------------------------------------------------------------------------------+
| @@GLOBAL.GTID_EXECUTED |
+-------------------------------------------------------------------------------------+
| 20e43bc1-48a8-11ee-8646-005056a76880:1-8,
6a34717b-c0c8-11ee-9428-005056bf0687:1-11 |
+-------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
4.从库
--设置GTID位置:需要把主库设置过的GTID全部设置.
--否则出现:and the missing transactions are '20e43bc1-48a8-11ee-8646-005056a76880:1-2'
reset master;
reset slave all;
SET @@GLOBAL.GTID_PURGED='20e43bc1-48a8-11ee-8646-005056a76880:1-8,6a34717b-c0c8-11ee-9428-005056bf0687:1-11';
mysql> CHANGE MASTER TO MASTER_HOST='10.1.1.1',MASTER_PORT=3300,MASTER_USER='repl',MASTER_PASSWORD='repl4slave',MASTER_AUTO_POSITION=1;
Query OK, 0 rows affected, 8 warnings (0.01 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 10.1.1.1
Master_User: repl
Master_Port: 3300
Connect_Retry: 60
Master_Log_File:
Read_Master_Log_Pos: 4
Relay_Log_File: configcenter-prod-mysql8-local-slave-20240201-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File:
Slave_IO_Running: No
Slave_SQL_Running: No
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: 0
Relay_Log_Space: 157
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: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_UUID:
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
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: 20e43bc1-48a8-11ee-8646-005056a76880:1-8,
6a34717b-c0c8-11ee-9428-005056bf0687:1-11
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.00 sec)
ERROR:
No query specified
5.启动基于GTID的同步。
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: 10.1.1.1
Master_User: repl
Master_Port: 3300
Connect_Retry: 60
Master_Log_File: binlog.000015
Read_Master_Log_Pos: 2255
Relay_Log_File: configcenter-prod-mysql8-local-slave-20240201-relay-bin.000002
Relay_Log_Pos: 411
Relay_Master_Log_File: binlog.000015
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: 2255
Relay_Log_Space: 661
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: 133001
Master_UUID: 6a34717b-c0c8-11ee-9428-005056bf0687
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Replica 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: 20e43bc1-48a8-11ee-8646-005056a76880:1-8,
6a34717b-c0c8-11ee-9428-005056bf0687:1-11
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.00 sec)
ERROR:
No query specified
6.总结
开启基于GTID的同步,需要首先设置从库的GTID_PURGED的值,并且该值和主库完全一致。