---
title: "复制之跳过异常语句的操作"
author: "jahu"
date: "2017-02-28T15:46:27Z"
tags: []
categories: ["数据库"]
slug: "untitled"
draft: false
lastmod: "2017-02-28T17:19:59Z"
id: 2359504
url: "https://jahu.iteye.com/blog/2359504"
---

```
主健冲突或数据不一致的情况：
(1)停止slave进程
STOP SLAVE;    

(2)设置事务号，事务号从Retrieved_Gtid_Set获取

SET @@SESSION.GTID_NEXT= 'xxxxxxxxxxx'    

(3)设置空事务

BEGIN; COMMIT;    

(4)恢复事务号

SET SESSION GTID_NEXT = AUTOMATIC;    

(5)启动slave进程

START SLAVE;  

----------------------------------------------------------------------------------------
```

**5.reset master信息**

 

mysql&gt; reset master;

Query OK, 0 rows affected (0.11 sec)

 

mysql&gt; show master status;

+------------------+----------+--------------+------------------+-------------------+

| File             | Position | Binlog\_Do\_DB | Binlog\_Ignore\_DB | Executed\_Gtid\_Set |

+------------------+----------+--------------+------------------+-------------------+

| mysql-bin.000001 |      154 |              |                  |                   |

+------------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)

 

mysql&gt; show global variables like '%gtid%';

+----------------------------------+-------+

| Variable\_name                    | Value |

+----------------------------------+-------+

| binlog\_gtid\_simple\_recovery      | ON    |

| enforce\_gtid\_consistency         | ON    |

| **gtid\_executed**                    |       |

| gtid\_executed\_compression\_period | 1000  |

| gtid\_mode                        | ON    |

| gtid\_owned                       |       |

| **gtid\_purged**                      |       |

| session\_track\_gtids              | OFF   |

+----------------------------------+-------+

8 rows in set (0.01 sec)

 

**可以看到 gtid\_executed  和 gtid\_purged 已经没有gtid的信息了**

**--------------------------------------------------------------------------------------------------------------------------------**

**主从变成主主**

**change master to  master\_host='192.168.6.1',master\_port=3306 , master\_user='555',master\_password='123456' ,master\_auto\_position=1;**