Adsar Logo


MySQL - skip a replicated transaction



Sometimes you may run an update on a master node that causes the slave to cry (i.e. a missing table).

To skip a single transaction, run the following:

STOP SLAVE;
SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;
START SLAVE;

And if you want to automate this, in php:

<?php

$mysqli = new mysqli("localhost", "root", "PASSWORD");

while (true) {

    usleep(500000);
    
    $result = $mysqli->query("SELECT SERVICE_STATE FROM performance_schema.replication_applier_status;");
    $row = $result->fetch_assoc();

    var_dump($row['SERVICE_STATE']);
    
    if ($row['SERVICE_STATE']!="OFF") exit;
    
    
    $mysqli->query("STOP SLAVE");
    $mysqli->query("SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;");
    $mysqli->query("START SLAVE;");
    
}


Trees for life


Want to get in touch? mail@adsar.co.uk