基本的M-S结构
 
现在master与slave主机数据一致:
 
mysql> select * from t1;
+------+
| id   |
+------+
|    1 |
|    2 |
|    4 |
+------+
3 rows in set (0.00 sec)
 
我们来模拟故障现象:
在master上,通过设置sql_log_bin来控制命令是否写入二进制日志中,运行命令:
set sql_log_bin=OFF;
insert into t1 values(5);
set sql_log_bin=ON;
insert into t1 values(6);
这样数据在master上是这样的:

mysql> select * from t1;
+------+
| id |
+------+
| 1 |
| 2 |
| 4 |
| 5 |
| 6 |
+------+
5 rows in set (0.00 sec)
而在slave上的数据是这样的:
mysql> select * from testdb.t1;
+------+
| id |
+------+
| 1 |
| 2 |
| 4 |
| 6 |
+------+
4 rows in set (0.00 sec)
此时我们在master上执行操作:
update t1 set id=7 where id=5;
insert into t1 values(8); mysql> select * from t1;
+------+
| id |
+------+
| 1 |
| 2 |
| 4 |
| 7 |
| 6 |
| 8 |
+------+
6 rows in set (0.00 sec)
我们查询一下slave上的数据:
mysql> select * from testdb.t1;
+------+
| id |
+------+
| 1 |
| 2 |
| 4 |
| 6 |
+------+
4 rows in set (0.00 sec)
发现数据并没有被同步过来,我们来show一下slave
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.203.135
Master_User: replmonitor
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: host2-bin.000002
Read_Master_Log_Pos: 1146
Relay_Log_File: host3-relay-bin.000003
Relay_Log_Pos: 648
Relay_Master_Log_File: host2-bin.000002
Slave_IO_Running: Yes
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: 1032
Last_Error: Could not execute Update_rows event on table testdb.t1; Can't find record in 't1', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log host2-bin.000002, end_log_pos 875
Skip_Counter: 0
Exec_Master_Log_Pos: 660
Relay_Log_Space: 1595
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: 1032
Last_SQL_Error: Could not execute Update_rows event on table testdb.t1; Can't find record in 't1', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log host2-bin.000002, end_log_pos 875
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2
Master_UUID: cd32a980-2a97-11e5-a344-000c2954ccde
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: 150717 23:51:51
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: cd32a980-2a97-11e5-a344-000c2954ccde:1-3
Executed_Gtid_Set: cd32a980-2a97-11e5-a344-000c2954ccde:1
Auto_Position: 1
1 row in set (0.00 sec)
此时我们查看一下错误日志:
 
2015-07-17 23:51:51 30750 [ERROR] Slave SQL: Could not execute Update_rows event on table testdb.t1; Can't find record in 't1', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log host2-bin.000002, end_log_pos 875, Error_code: 1032
2015-07-17 23:51:51 30750 [Warning] Slave: Can't find record in 't1' Error_code: 1032
2015-07-17 23:51:51 30750 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'host2-bin.000002' position 660
 
提示我们在修改错误并重新启动slave,但关键在于如何修正错误,一般我们采用如下方法:
 
在从机slave上执行:
 
mysql> stop slave;
Query OK, 0 rows affected (0.02 sec) mysql> set gtid_next='cd32a980-2a97-11e5-a344-000c2954ccde:2';
Query OK, 0 rows affected (0.00 sec) mysql> begin;
Query OK, 0 rows affected (0.00 sec) mysql> commit;
Query OK, 0 rows affected (0.00 sec) mysql> set gtid_next='AUTOMATIC';
Query OK, 0 rows affected (0.00 sec) mysql> start slave;
Query OK, 0 rows affected (0.01 sec) 即跳过有错误的GTID编号
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.203.135
Master_User: replmonitor
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: host2-bin.000002
Read_Master_Log_Pos: 1146
Relay_Log_File: host3-relay-bin.000005
Relay_Log_Pos: 688
Relay_Master_Log_File: host2-bin.000002
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: 1146
Relay_Log_Space: 1429
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: 2
Master_UUID: cd32a980-2a97-11e5-a344-000c2954ccde
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: cd32a980-2a97-11e5-a344-000c2954ccde:1-3
Executed_Gtid_Set: cd32a980-2a97-11e5-a344-000c2954ccde:1-3
Auto_Position: 1
1 row in set (0.00 sec) mysql> select * from testdb.t1;
+------+
| id |
+------+
| 1 |
| 2 |
| 4 |
| 6 |
| 8 |
+------+
5 rows in set (0.00 sec)
可以发现事务已经全部同步了,但现在数据却是不一致的。
这种适合在数据要求不高的情况下使用,如果后续还有其它数据操作,造成主从数据差异过大,就得用从主库的一个完整备份过来,再从某点开始做replication。
 
 
 
 

基于GTID Replication主从数据不一致操作的更多相关文章

  1. 基于GTID搭建主从MySQL

    目录 基于gtid搭建主从MySQL 一.GTID的使用 二.GTID的简介 三.GTID的构成 四.查看GTID的执行情况 4.1 gtid_executed 4.2 gtid_own 4.3 gt ...

  2. MySQL多字节字符集造成主从数据不一致问题

    MySQL多字节字符集造成主从数据不一致问题 来自江羽   2013-04-27 16:03:56|  分类: 默认分类|举报|字号 订阅 转载: http://backend.blog.163.co ...

  3. pt-table-checksum检验主从数据不一致

    测试环境:主从架构,操作系统liunx 运行pt-table-checksum需要先安装以下依赖包: yum install perl-IO-Socket-SSL perl-DBD-MySQL per ...

  4. mysql 主从 数据不一致

    用pt-table-checksum校验数据一致性 Jun 4th, 2013 主从数据的一致性校验是个头疼的问题,偶尔被业务投诉主从数据不一致,或者几个从库之间的 数据不一致,这会令人沮丧.通常我们 ...

  5. 揭秘MySQL主从数据不一致

    前言: 目前MySQL数据库最常用的是主从架构,大多数高可用架构也是通过主从架构演变而来.但是主从架构运行时间长久后容易出现数据不一致的情况,比如因从库可写造成的误操作或者复制bug等,本篇文章将会详 ...

  6. mysql]一次主从数据不一致的问题解决过程()

    问题 要解决问题就是怎么对比不一致,然后在不影响业务的情况下,修复数据不一致的问题,把从库缺少的数据补上 下面是能想到和找到的几个方案 1 从新从0开始同步,虽然对主库的使用没有影响,但是那么大的数据 ...

  7. [mysql]一次主从数据不一致的问题解决过程

    之前一篇: 主从更换ip之后重新建立同步 情况时这样的 昨天晚上主动2个机器都迁移了,然后今天才把主动重新连接上,但是从库的偏移量是从今天当前时刻开始的,也就是说虽然现在主动看似正常,其实是少了昨天的 ...

  8. 基于GTID的主从架构异常处理流程

    通常情况下我们主库的binlog只保留7天,如果从库故障超过7天以上的数据没有同步的话,那么主从架构就会异常,需要重新搭建主从架构. 本文就简单说明下如何通过mysqldump主库的数据恢复从库的主从 ...

  9. mysql 主从数据不一致 Slave_SQL_Running: No 解决方法

    在slave服务器上通过如下命令 mysql> show slave status\G; 显示如下情况: Slave_IO_Running: Yes Slave_SQL_Running: No ...

随机推荐

  1. 一个3D的多人在线游戏, 服务端 + 客户端 【转】

    最近学院组织了一个实训,要求是利用Socket通信和D3D的知识, 写一个多人在线的游戏, 服务端是在linux下, 客户是在Windows下: 写这个的目的是想让大家给我找错, 欢迎大家的意见.我的 ...

  2. 项“XXXXX.sln”已在选择的位置受源代码管理

    项“XXXXX.sln”已在选择的位置受源代码管理.如果尝试重新绑定已在 Microsoft Visual Studio 外部添加到源代码管理的项目,应使用“更改源代码管理”命令.如果是第一次添加此项 ...

  3. asp.net 的page 基类页面 做一些判断 可以定义一个基类页面 继承Page类 然后重写OnPreLoad事件

    public class BasePage:Page protected override void OnPreLoad(EventArgs e){     base.OnPreLoad(e);    ...

  4. Javascript中使用WScript.Shell对象执行.bat文件和cmd命令

    WScript.Shell(Windows Script Host Runtime Library)是一个对象,对应的文件是C:/WINDOWS/system32/wshom.ocx,Wscript. ...

  5. wordpress自动保存远程图片插件 DX-auto-save-images

    wordpress自动保存远程图片插件DX-auto-save-images 解决了保存文章就可以自动将远程图片保存到你的服务器上了. 具体操作步骤如下: 1.安装启用wordpress自动保存远程图 ...

  6. 使用proxool 连接池:No suitable driver found for proxool

    使用proxool连接池时:报错误No suitable driver found for proxool.shide的原因: ①.WEB-INF目录下的lib中没有proxool连接池jar驱动包. ...

  7. Android adt v22.6.2 自动创建 appcompat_v7 解决方法,最低版本2.2也不会出现

    Android 开发工具升级到22.6.2在创建工程时只要选择的最低版本低于4.0,就会自动生成一个项目appcompat_v7,没创建一个新的项目都会自动创建,很是烦恼... 之前在网上也找过方法, ...

  8. Equals Finalize GetHashCode GetType MemberwiseClone ReferenceEquals ToString String.IsInterned

    参考资料: http://blog.csdn.net/afgasdg/article/details/6889383 http://www.cnblogs.com/skyivben/archive/2 ...

  9. 网络存储-Samba、NAS---未知的用户名或错误密码

    项目中的文件需要保存到网络存储设备中,之前用的是NAS.因没来得及采购就先用Samba顶上.代码发现通用…… 一.定义: Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器 ...

  10. saiku之行速度优化(三)

    经历了前两轮优化之后,saiku由不可使用,优化到可以使用,不过在分析大量日志数据的时候,还有顿卡的感觉!继续观察背后执行的Sql,决定将注意力关注到索引上面! 日志的主要使用场景是:固定日期维度的数 ...