Event description
I did a read-write separation experiment on the virtual machine. After the end, I found that the slave SQL process stopped from the server. The first reaction at that time was that the master-bin binary file had a problem.
mysql> show slave status\G; //在slave上查看的状态记录
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 20.0.0.12
Master_User: myslave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000007
Read_Master_Log_Pos: 154
Relay_Log_File: relay-log-bin.000019
Relay_Log_Pos: 677
Relay_Master_Log_File: master-bin.000006
Slave_IO_Running: Yes
Slave_SQL_Running: No
After that, I went to the master to check the status, and found that there was no abnormality, and the binary files were compared correctly. Thinking left and right, it may be related to the separation test of reading and writing today. It may be that in the final verification stage of the test, the operation of writing data from the server to test the test results caused the SQL thread to be abnormal.
mysql> show master status; //查看master状态
+-------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| master-bin.000007 | 154 | | | |
+-------------------+----------+--------------+------------------+-------------------+
Solution
After verification, it is indeed caused by writing data on the slave server. The solution is as follows:
- stop slave; //Close the master and slave first
- set GLOBAL SQL_SLAVE_SKIP_COUNTER=1; //Set to skip the last error
- start slave; //Start the master and slave again
mysql> stop slave ; //先关闭主从
Query OK, 0 rows affected (0.00 sec)
mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1; //设置跳过上一次错误
Query OK, 0 rows affected (0.00 sec)
mysql> start slave ; //再次开启主从
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G; //查看,状态已经正常了
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 20.0.0.12
Master_User: myslave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000007
Read_Master_Log_Pos: 419
Relay_Log_File: relay-log-bin.000021
Relay_Log_Pos: 321
Relay_Master_Log_File: master-bin.000007
Slave_IO_Running: Yes
Slave_SQL_Running: Yes