一、在线添加从库

主集群: 10.1.1.23:5306

从集群: 10.1.3.88:5306

主库开启binlog

MySQL [(none)]> CREATE BINLOG 'clustrix-bin' FORMAT='ROW'

主库创建同步账号

MySQL [(none)]> create user 'clx_repl'@'%' identified by '123123';

MySQL [(none)]> Grant REPLICATION SLAVE ON *.* to 'clx_repl'@'%';

主库模拟创建数据

scloudusr@p2cn1uclx101m_10.248.100.241 ~]$ sysbench --mysql-host=localhost --mysql-port=5306 --mysql-user=root --mysql-password= --mysql-db=scloud --table_size=1000000 oltp_insert prepare

主库备份数据

MySQL [(none)]>  backup scloud.* to "sftp://scloudusr:Scloud201!@10.1.3.88:2022/tmp/backup" ;

从库恢复数据

RESTORE * FROM "sftp://scloudusr:Scloud201!@10.1.3.88:2022/tmp/backup" REPLICAS = 1;   (快速恢复使用1个副本)

从库备份文件找到主库file和pos信息

cat /tmp/backup/metadata/clustrix-bin.000002:103179247

从库配置同步信息

MySQL [(none)]> stop slave;
MySQL [(none)]> CHANGE MASTER TO MASTER_LOG_FILE = 'clustrix-bin.000002', MASTER_LOG_POS = 103179247, MASTER_HOST = '10.1.1.23', MASTER_USER = 'clx_repl', MASTER_PASSWORD = '123123', MASTER_PORT = 5306;
MySQL [(none)]> start slave;
MySQL [(none)]> show slave status\G

MySQL [scloud]> show slave status\G

*************************** 1. row ***************************

Slave_Name: default

Slave_Status: Running

Master_Host: 10.1.1.23

Master_Port: 5306

Master_User: clx_repl

Master_Log_File: clustrix-bin

Slave_Enabled: Enabled

Log_File_Seq: 3

Log_File_Pos: 26232091

Last_Error: no error

Connection_Status: Connected

Relay_Log_Bytes_Read: 0

Relay_Log_Current_Bytes: 12483

  Seconds_Behind_Master: 225

1 row in set (0.00 sec)

二、主从同步异常处理

通过stop slave;  start slave skip 1; 来跳过错误事务

MySQL [test]> show slave status\G
*************************** 1. row ***************************
Slave_Name: default
Slave_Status: Errored
Master_Host: 10.1.3.151
Master_Port: 5306
Master_User: clx_repl
Master_Log_File: clustrix-bin
Slave_Enabled: Enabled
Log_File_Seq: 2
Log_File_Pos: 102189775
Last_Error: Row Not Found: for delete on test.tt at clustrix-bin2.102189909 where tt.__idx_tt__PRIMARY(id)=(3). Statement: COMMIT, Database:
Connection_Status: Disconnected
Relay_Log_Bytes_Read: 0
Relay_Log_Current_Bytes: 0
Seconds_Behind_Master: NULL
1 row in set (0.00 sec)

MySQL [test]> stop slave;
Query OK, 0 rows affected (0.01 sec)

MySQL [test]> start slave skip 1;
Query OK, 0 rows affected (0.01 sec)

MySQL [test]> show slave status\G
*************************** 1. row ***************************
Slave_Name: default
Slave_Status: Running
Master_Host: 10.1.3.151
Master_Port: 5306
Master_User: clx_repl
Master_Log_File: clustrix-bin
Slave_Enabled: Enabled
Log_File_Seq: 2
Log_File_Pos: 102189969
Last_Error: no error
Connection_Status: Connected
Relay_Log_Bytes_Read: 0
Relay_Log_Current_Bytes: 0
Seconds_Behind_Master: 0
1 row in set (0.00 sec)

最新文章

  1. JavaScript语言精粹--Function,类,this,对象
  2. 课堂Java小程序(加减乘除与验证码)
  3. mongodb架构篇
  4. VC++/MFC 最常用宏和指令
  5. hibernate的session对象核心方法注意的问题
  6. cpu和io进程调度时间
  7. Unresolved external 'LresultFromObject'
  8. ios创建bundle的图片资源文件(转)
  9. c# dataset 索引0没有值
  10. POJ 1323 Game Prediction#贪心
  11. 数字规律:Pascal‘s triangle
  12. winow7安装django 1.9.1
  13. 学习笔记:javascript内置对象:字符串对象
  14. .NET作品集:linux下的博客程序
  15. shell入门之变量测试
  16. sql server创建登录出发器后导致登录失败--解决方案
  17. Perl处理和收走子进程(退出状态码和wait)
  18. ASP.NET Web API相关
  19. 【CSS】面试知识整理
  20. 依赖注入(Dependency Injection)

热门文章

  1. 简述前后端项目RSA+AES加解密
  2. 20191224 Spring官方文档(Core 1.1-1.4)
  3. mysql——触发器——概念
  4. poj1284(欧拉函数+原根)
  5. etcd集群移除节点
  6. linux项目运行环境搭建
  7. Object的create、assign、getPrototypeOf与拷贝
  8. [LeetCode] 226. 用队列实现栈
  9. python网络爬虫(1)静态网页抓取
  10. Doker GRPC "Connection reset by peer"