(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)
#在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*/;