mysql5.6主从复制日志应用错误

今天做主从测试,在从库进行日志应用的时候报了一个错,导致从库的slave IO sql应用进程停止工作,报了一个下面的错:

mysql> show slave status \G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 127.0.0.1
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: binlog.000018
          Read_Master_Log_Pos: 2807
               Relay_Log_File: relaylog.000002
                Relay_Log_Pos: 1279
        Relay_Master_Log_File: binlog.000018
             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: 1141
                   Last_Error: Error 'There is no such grant defined for user 'wufan' on host '%'' on query. Default database: 'test'. Query: 'revoke SELECT ON `jfedu`.* from wufan@'%''
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1717
              Relay_Log_Space: 3656
              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: 1141
               Last_SQL_Error: Error 'There is no such grant defined for user 'wufan' on host '%'' on query. Default database: 'test'. Query: 'revoke SELECT ON `jfedu`.* from wufan@'%''
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 101
                  Master_UUID: 36020f29-004a-11e8-9f6a-080027293866
             Master_Info_File: /u01/my3307/data/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: 180203 18:05:22
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
1 row in set (0.00 sec)

ERROR: 
No query specified
1,在主库上执行了revoke all privileges on *.* from wufan@'%' ;

2,从库同时也会执行这样语句,但是由于从库并没有wufan这个用户,所以必然报错



可以看到,从主库复制binlog的salve_io线程还在忙活,但是执行从库更新的slave_sql已经罢工了,从Last_error:可以看到是因为执行主库执行跟wufan用户相关的权限操作时报的错。
There is no such grant defined for user 'wufan' on host '%'' on query. Default database: 'test'. Query: 'revoke SELECT ON `jfedu`.* from wufan@'%''

此时可以通过使从库跳过这一错误事件继续运行下面的日志应用:

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.00 sec) 

上面的语句是告诉slave跳过当前卡住的event,然后重新起来干活。

查看一下slave的状态:

mysql> show slave status \G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 127.0.0.1
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: binlog.000018
          Read_Master_Log_Pos: 2807
               Relay_Log_File: relaylog.000006
                Relay_Log_Pos: 280
        Relay_Master_Log_File: binlog.000018
             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: 2807
              Relay_Log_Space: 606
              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: 101
                  Master_UUID: 36020f29-004a-11e8-9f6a-080027293866
             Master_Info_File: /u01/my3307/data/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: 
                Auto_Position: 0
1 row in set (0.00 sec)

ERROR: 
No query specified
注意这两个信息:

Slave_IO_Running: Yes
Slave_SQL_Running: Yes
发现日志获取io进程和sql应用进程都正常了。

上面的方法在slave比较少的时候还可以,但是当从库有几十台时,逐台去处理既费时又容易出错,怎样在主库这一侧一劳永逸地避免呢?

对,就是在主库这侧不要将这样的grant语句写入到binlog中,MySQL不愧世界级的软件产品,它提供了一个session粒度的选项,通过关闭这个选项可以不让主库将打开这个选项或关闭连接前的SQL语句写入binlog。

在主库侧执行下面的命令临时关闭binlog日志,然后需要的时候在启动binlog日志

1
2
mysql>set sql_log_bin=off;
mysql>revoke all privileges on *.* from wufan@'%' ;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值