设为首页 收藏本站
查看: 282|回复: 0

[经验分享] mysql5.6 传统复制模式下1032和1062故障处理

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-12-13 08:21:06 | 显示全部楼层 |阅读模式
一、环境
master     172.16.1.61      3307
slave      172.16.1.62      3307

二、检查环境
在master上检查
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(root@127.0.0.1) [(none)]>show processlist\G
*************************** 1. row ***************************
     Id: 2
   User: root
   Host: localhost:42483
     db: NULL
Command: Query
   Time: 0
  State: init
   Info: show processlist
*************************** 2. row ***************************
     Id: 6
   User: repl
   Host: 172.16.1.62:35506
     db: NULL
Command: Binlog Dump
   Time: 84
  State: Master has sent all binlog to slave; waiting for binlog to be updated
   Info: NULL
2 rows in set (0.00 sec)



在slave上检查
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(root@127.0.0.1) [(none)]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 500
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 380
        Relay_Master_Log_File: mybinlog3307.000007
             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: 500
              Relay_Log_Space: 555
              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: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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:
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0            #这里的值为0,表示是传统复制
1 row in set (0.00 sec)



三、模拟1062错误故障

1062错误是由于主键冲突引起的
在master创建一个表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#创建表t1
(root@127.0.0.1) [lyao]>create table t1(id int not null auto_increment, name varchar(30), primary key(id));
Query OK, 0 rows affected (0.37 sec)

(root@127.0.0.1) [lyao]>show tables;
+----------------+
| Tables_in_lyao |
+----------------+
| t1             |
+----------------+
1 row in set (0.00 sec)

(root@127.0.0.1) [lyao]>show create table t1;
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                             |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

#在slave上查看结果
(root@127.0.0.1) [lyao]>show tables;
+----------------+
| Tables_in_lyao |
+----------------+
| t1             |
+----------------+
1 row in set (0.00 sec)

#在master上插入2条数据
(root@127.0.0.1) [lyao]>insert into t1(name) values('beijing');
Query OK, 1 row affected (0.31 sec)

(root@127.0.0.1) [lyao]>insert into t1(name) values('shenzhen');
Query OK, 1 row affected (0.02 sec)

(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
+----+----------+
2 rows in set (0.00 sec)

#在slave上查看主从状态以及相应的表结果
(root@127.0.0.1) [lyao]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 1055
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 935
        Relay_Master_Log_File: mybinlog3307.000007
             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: 1055
              Relay_Log_Space: 1110
              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: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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:
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0
1 row in set (0.00 sec)

(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
+----+----------+
2 rows in set (0.01 sec)
#结果表示一切正常



从上面的结果看出结果一切正常的,现在我们来模拟主键冲突的错误
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#在slave上插入一条数据
(root@127.0.0.1) [lyao]>insert into t1(name) values('hangzhou');
Query OK, 1 row affected (0.31 sec)

#查看表结果
(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
|  3 | hangzhou |
+----+----------+
3 rows in set (0.00 sec)

#查看主从状态结果,没有任何错误
(root@127.0.0.1) [lyao]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 1055
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 935
        Relay_Master_Log_File: mybinlog3307.000007
             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: 1055
              Relay_Log_Space: 1110
              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: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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:
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0
1 row in set (0.00 sec)

#现在在master上插入一条语句name='shanghai'的值
(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
+----+----------+
2 rows in set (0.00 sec)

(root@127.0.0.1) [lyao]>insert into t1(name) values('shanghai');
Query OK, 1 row affected (0.01 sec)

(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
|  3 | shanghai |
+----+----------+
3 rows in set (0.00 sec)

#在slave上查看表结果
(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
|  3 | hangzhou |            #这条记录还是之前的,新的数据并没有同步过来
+----+----------+
3 rows in set (0.00 sec)

#查看主从状态
(root@127.0.0.1) [lyao]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 1255
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 935
        Relay_Master_Log_File: mybinlog3307.000007
             Slave_IO_Running: Yes
            Slave_SQL_Running: No            #SQL线程已经停止
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 1062        #1062状态
                   Last_Error: Could not execute Write_rows event on table lyao.t1; Duplicate entry '3' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mybinlog3307.000007, end_log_pos 1224
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1055
              Relay_Log_Space: 1310
              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: 1062
               Last_SQL_Error: Could not execute Write_rows event on table lyao.t1; Duplicate entry '3' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mybinlog3307.000007, end_log_pos 1224
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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: 161212 16:48:57
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0
1 row in set (0.00 sec)


#从上面的结果能看出,slave上表t1中id=3的值存在引起的。
(root@127.0.0.1) [lyao]>select * from t1 where id=3;
+----+----------+
| id | name     |
+----+----------+
|  3 | hangzhou |
+----+----------+
1 row in set (0.00 sec)
#这条结果真的存在,但是这条数据不是我们要的,我们可以考虑删除该语句,恢复主从同步
#如果这条语句需要保留可以考虑在master上插入一条语句解决问题

#这里我们采用删除该语句来恢复主从同步
(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
|  3 | hangzhou |
+----+----------+
3 rows in set (0.00 sec)


(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
+----+----------+
2 rows in set (0.00 sec)

#重新启动sql_thread线程
(root@127.0.0.1) [lyao]>start slave sql_thread;
Query OK, 0 rows affected (0.02 sec)

#查看主从状态
(root@127.0.0.1) [lyao]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 1255
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 1135
        Relay_Master_Log_File: mybinlog3307.000007
             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: 1255
              Relay_Log_Space: 1310
              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: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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:
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0
1 row in set (0.00 sec)



以上结果显示恢复正常

四、模拟1032错误故障
1032错误主要是由于记录不存在引起的
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#在master上查看表t1的结果
(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
|  3 | shanghai |
+----+----------+
3 rows in set (0.01 sec)

#在slave查看表t1的结果
(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
|  3 | shanghai |
+----+----------+
3 rows in set (0.00 sec)

#在slave上查看主从状态,结果正常
(root@127.0.0.1) [lyao]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 1255
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 1135
        Relay_Master_Log_File: mybinlog3307.000007
             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: 1255
              Relay_Log_Space: 1310
              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: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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:
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0
1 row in set (0.00 sec)

#在slave上从t1表中删除id=3的值,并查看主从状态,一切正常
(root@127.0.0.1) [lyao]>delete from t1 where id=3;
Query OK, 1 row affected (0.01 sec)

(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
+----+----------+
2 rows in set (0.00 sec)

(root@127.0.0.1) [lyao]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 1255
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 1135
        Relay_Master_Log_File: mybinlog3307.000007
             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: 1255
              Relay_Log_Space: 1310
              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: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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:
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0
1 row in set (0.00 sec)


#在master上将id=3的数据删除掉
(root@127.0.0.1) [lyao]>delete from t1 where id=3;
Query OK, 1 row affected (0.32 sec)

(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
+----+----------+
2 rows in set (0.00 sec)

#在slave上查看主从状态,可以看到已经显示1032错误状态
(root@127.0.0.1) [lyao]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 1455
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 1135
        Relay_Master_Log_File: mybinlog3307.000007
             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 Delete_rows event on table lyao.t1; Can't find record in 't1', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mybinlog3307.000007, end_log_pos 1424
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1255
              Relay_Log_Space: 1510
              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 Delete_rows event on table lyao.t1; Can't find record in 't1', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mybinlog3307.000007, end_log_pos 1424
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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: 161212 17:17:51
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0
1 row in set (0.00 sec)


#在master上查看binlog日志文件
[iyunv@mysql-1 ~]# mysqlbinlog --base64-output=decode-rows -v /data/mysql/data3307/mybinlog3307.000007 --start-position=1255 --stop-position=1424
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 1255
#161212 17:17:51 server id 103307  end_log_pos 1327 CRC32 0xaefdd0b1  Query   thread_id=2 exec_time=0 error_code=0
SET TIMESTAMP=1481534271/*!*/;
SET @@session.pseudo_thread_id=2/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1075838976/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
BEGIN
/*!*/;
# at 1327
#161212 17:17:51 server id 103307  end_log_pos 1375 CRC32 0xdf4dd67b  Table_map: `lyao`.`t1` mapped to number 70
# at 1375
#161212 17:17:51 server id 103307  end_log_pos 1424 CRC32 0xc1aaef42  Delete_rows: table id 70 flags: STMT_END_F
### DELETE FROM `lyao`.`t1`
### WHERE
###   @1=3
###   @2='shanghai'
DELIMITER ;
# End of log file            #这里的语句是引起1032的SQL语句
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;


#跳过这个sql语句
(root@127.0.0.1) [lyao]>set global sql_slave_skip_counter = 1;
Query OK, 0 rows affected (0.00 sec)


#重新启动sql_thread线程
(root@127.0.0.1) [lyao]>start slave sql_thread;
Query OK, 0 rows affected (0.02 sec)


#查看主从状态,故障解决
(root@127.0.0.1) [lyao]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 1455
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 1335
        Relay_Master_Log_File: mybinlog3307.000007
             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: 1455
              Relay_Log_Space: 1510
              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: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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:
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0
1 row in set (0.00 sec)



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-313459-1-1.html 上篇帖子: MHA架构概述及实战 下篇帖子: mysqldump常用命令选项
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表