MySQL主从同步复制,出现Slave_SQL_Running: No故障!!!

事件描述

在虚拟机上做读写分离实验,结束后就发现slave从服务器SQL进程停止了,当时第一反应是master-bin二进制文件出了问题

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

之后就去master上查看状态,发现并无异常,二进制文件也是对比无误。左思右想,可能与今天做的读写分离试验有关。可能是在试验最后验证阶段,在从服务器写入数据测验试验结果的操作导致SQL线程异常。

mysql> show master status;    //查看master状态
+-------------------+----------+--------------+------------------+-------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| master-bin.000007 |      154 |              |                  |                   |
+-------------------+----------+--------------+------------------+-------------------+

解决办法

经过验证,确实是在slave服务器写入数据造成的异常,解决办法如下:

  1. stop slave ; //先关闭主从
  2. set GLOBAL SQL_SLAVE_SKIP_COUNTER=1; //设置跳过上一次错误
  3. start slave ; //再次开启主从
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

你可能感兴趣的:(数据库管理,排障集合,mysql,数据库,linux)