The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mojar::Mysql::Replication - Monitor and control the replication threads

SYNOPSIS

  use Mojar::Mysql::Replication;
  my $repl = Mojar::Mysql::Replication->new(connector => ...);
  say 'Lag: ', $repl->sql_lag;

DESCRIPTION

A class for monitoring and managing replication threads.

USAGE

First create a replication object (manager) that knows how to connect to the replicating database.

  use Mojar::Mysql::Replication;
  use Mojar::Mysql::Connector (
    cnf => '...',
    -connector => 1
  );
  my $repl = Mojar::Mysql::Replication->new(
    connector => $self->connector,
    log => $self->log
  );

Then you can monitor the status of its replication.

  $connection_time = $repl->io_run_time;
  $lag = $repl->sql_lag;
  $required_binlog = $repl->status->{master_log_file};

And you can manage replication.

  $repl->safety('max_safety')->stop;
  $repl->start_io->start_sql;

RATIONALE

Replication is most often used for scaling out for performance, protection from potentially interfering readers, and data security. There are, however, very few tools to help monitor and manage replication, probably due to the fiddliness of the details. At one site this package helps manage 100+ MySQL servers.

COPYRIGHT AND LICENCE

Copyright (C) 2006--2014, Nic Sandfield.

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.

SEE ALSO

MySQL manual, Percona Toolkit.