set sql_log_bin=0 #暂停二进制复制 show processlist #查看线程 show status like '%semi%'; #查看半同步状态 show slave status \G; #查看从库状态 show variables like '%binlog%' #查看变量
create user repluser@'%' identified by '123456@Root' grant replication all on *.* to repluser@'%' #查看主库状态,记录同步日志点 show master status;
CHANGE MASTER TO MASTER_HOST='10.1.0.18', MASTER_USER='repluser', MASTER_PASSWORD='123456@Root', MASTER_PORT=3306, MASTER_LOG_FILE='binlog.000021', MASTER_LOG_POS=157
#查看从库状态 show slave status;
4.开启同步
1 2 3
start slave; show processlist; #查看线程 show slave status; #查看从库状态
5.复制错误跟踪日志
1 2 3 4 5 6 7 8 9 10 11 12 13 14
select * from performance_schema.replication_applier_status_by_worker \G; # Worker 1 failed executing transaction 'ANONYMOUS' at source log binlog.000021, end_log_pos 780; Error 'Operation CREATE USER failed for 'repluser'@'%'' on query. Default database: 'mysql'. Query: 'CREATE USER 'repluser'@'%' IDENTIFIED WITH 'caching_sha2_password' AS '$A$005$*q]Vu@ZX)60QO{hbcQVLFFwPpGhdPYOQ9EbulU21d1bQVsyKo.f/nUKZB'' 此错误为在从库上手动添加了同步用户。可以在binlog中找到这个pos点,跳过这个点后往后继续执行
MySQL主从复制报错Authentication plugin ‘caching_sha2_password‘ reported error: Authentication #主库执行 ALTER USER 'repluser'@'%' IDENTIFIED WITH mysql_native_password BY '123456@Root';