MySQL主从复制遇到的错误及解决方法

Posted tangpoets

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL主从复制遇到的错误及解决方法相关的知识,希望对你有一定的参考价值。

mysql在主从复制的时候经常遇到错误而导致Slave复制中断,这个时候就需要人工干涉,来跳过这个错误,才能使Slave端的复制,得以继续进行;

错误示例:

直接跳过一个事物,从而恢复正常主从同步。

 1 mysql> show slave status G
 2 *************************** 1. row ***************************
 3                Slave_IO_State: Waiting for master to send event
 4                   Master_Host: xxx.xx.xx.xx
 5                   Master_User: root
 6                   Master_Port: 3306
 7                 Connect_Retry: 60
 8               Master_Log_File: mysql-bin.002809
 9           Read_Master_Log_Pos: 458371658
10                Relay_Log_File: mysql-relay-bin.005184
11                 Relay_Log_Pos: 198543619
12         Relay_Master_Log_File: mysql-bin.002809
13              Slave_IO_Running: Yes
14             Slave_SQL_Running: No
15               Replicate_Do_DB: 
16           Replicate_Ignore_DB: SBZS
17            Replicate_Do_Table: 
18        Replicate_Ignore_Table: 
19       Replicate_Wild_Do_Table: 
20   Replicate_Wild_Ignore_Table: 
21                    Last_Errno: 1008
22                    Last_Error: Error Cant drop database SXZC; database doesnt exist on query. Default database: SXZC. Query: drop database SXZC
23                  Skip_Counter: 0
24           Exec_Master_Log_Pos: 198543406
25               Relay_Log_Space: 458372498
26               Until_Condition: None
27                Until_Log_File: 
28                 Until_Log_Pos: 0
29            Master_SSL_Allowed: No
30            Master_SSL_CA_File: 
31            Master_SSL_CA_Path: 
32               Master_SSL_Cert: 
33             Master_SSL_Cipher: 
34                Master_SSL_Key: 
35         Seconds_Behind_Master: NULL
36 Master_SSL_Verify_Server_Cert: No
37                 Last_IO_Errno: 0
38                 Last_IO_Error: 
39                Last_SQL_Errno: 1008
40                Last_SQL_Error: Error Cant drop database SXZC; database doesnt exist on query. Default database: SXZC. Query: drop database SXZC
41   Replicate_Ignore_Server_Ids: 
42              Master_Server_Id: 41
43                   Master_UUID: 7eab23eb-8965-11e7-8818-9c37f480e5a7
44              Master_Info_File: /opt/data/mysql/ptzc/master.info
45                     SQL_Delay: 0
46           SQL_Remaining_Delay: NULL
47       Slave_SQL_Running_State: 
48            Master_Retry_Count: 86400
49                   Master_Bind: 
50       Last_IO_Error_Timestamp: 
51      Last_SQL_Error_Timestamp: 180622 16:22:22
52                Master_SSL_Crl: 
53            Master_SSL_Crlpath: 
54            Retrieved_Gtid_Set: 
55             Executed_Gtid_Set: 
56                 Auto_Position: 0
57          Replicate_Rewrite_DB: 
58                  Channel_Name: 
59            Master_TLS_Version: 
60 1 row in set (0.00 sec)
 1 mysql> stop slave;
 2 Query OK, 0 rows affected (0.06 sec)
 3 
 4 mysql> SET GLOBAL  SQL_SLAVE_SKIP_COUNTER=1;
 5 Query OK, 0 rows affected (0.00 sec)
 6 
 7 mysql> SHOW GLOBAL VARIABLES LIKE SQL_SLAVE_SKIP_COUNTER;
 8 +------------------------+-------+
 9 | Variable_name          | Value |
10 +------------------------+-------+
11 | sql_slave_skip_counter | 1     |
12 +------------------------+-------+
13 1 row in set (0.02 sec)
14 
15 mysql> start slave;
16 Query OK, 0 rows affected (0.01 sec)
17 
18 mysql> show slave status G
19 *************************** 1. row ***************************
20                Slave_IO_State: Waiting for master to send event
21                   Master_Host: xxxx.xx.xx.xx
22                   Master_User: root
23                   Master_Port: 3306
24                 Connect_Retry: 60
25               Master_Log_File: mysql-bin.002809
26           Read_Master_Log_Pos: 459262133
27                Relay_Log_File: mysql-relay-bin.005184
28                 Relay_Log_Pos: 200420681
29         Relay_Master_Log_File: mysql-bin.002809
30              Slave_IO_Running: Yes
31             Slave_SQL_Running: Yes
32               Replicate_Do_DB: 
33           Replicate_Ignore_DB: SBZS
34            Replicate_Do_Table: 
35        Replicate_Ignore_Table: 
36       Replicate_Wild_Do_Table: 
37   Replicate_Wild_Ignore_Table: 
38                    Last_Errno: 0
39                    Last_Error: 
40                  Skip_Counter: 0
41           Exec_Master_Log_Pos: 200420468
42               Relay_Log_Space: 459263346
43               Until_Condition: None
44                Until_Log_File: 
45                 Until_Log_Pos: 0
46            Master_SSL_Allowed: No
47            Master_SSL_CA_File: 
48            Master_SSL_CA_Path: 
49               Master_SSL_Cert: 
50             Master_SSL_Cipher: 
51                Master_SSL_Key: 
52         Seconds_Behind_Master: 3760
53 Master_SSL_Verify_Server_Cert: No
54                 Last_IO_Errno: 0
55                 Last_IO_Error: 
56                Last_SQL_Errno: 0
57                Last_SQL_Error: 
58   Replicate_Ignore_Server_Ids: 
59              Master_Server_Id: 41
60                   Master_UUID: 7eab23eb-8965-11e7-8818-9c37f480e5a7
61              Master_Info_File: /opt/data/mysql/ptzc/master.info
62                     SQL_Delay: 0
63           SQL_Remaining_Delay: NULL
64       Slave_SQL_Running_State: update
65            Master_Retry_Count: 86400
66                   Master_Bind: 
67       Last_IO_Error_Timestamp: 
68      Last_SQL_Error_Timestamp: 
69                Master_SSL_Crl: 
70            Master_SSL_Crlpath: 
71            Retrieved_Gtid_Set: 
72             Executed_Gtid_Set: 
73                 Auto_Position: 0
74          Replicate_Rewrite_DB: 
75                  Channel_Name: 
76            Master_TLS_Version: 
77 1 row in set (0.00 sec)

 

以上是关于MySQL主从复制遇到的错误及解决方法的主要内容,如果未能解决你的问题,请参考以下文章

MySQL主从复制出错的解决方法

MySQL主从多种架构部署及常见错误问题解析

MySQL主从复制遇到错误的处理办法

13产生MySQL主从同步延迟的问题及解决方案

MySQL主从延迟复制实践及生产故障案例恢复实践

mysql 主从复制延迟及解决