Mysql::Replication
Replication functions for working with MySQL replication
See the description for each method below. The documentation for the methods is not fantastic yet so reviewing the code in mysql_replicate_manager.pl might be quite helpful.
To use a a method in this class, you must first request a Mysql::Replication object:
use Mysql::Replication; my $repl = Mysql::Replication->new();
You can then call subsequent methods with $repl->method();
Run the grant statement necessary to to set up a MySQL master
$repl->grant($dbh, $dot);
This runs the GRANT query that is necessary for setting up MySQL replication. See http://www.mysql.com/doc/en/Replication_HOWTO.html for more information. It logs into the MySQL master server and executes the command appropriate for the version of MySQL that you are using.
$dbh is a database handle and $dot is a hashref with variables read from the .my.cnf file. It expects at least the following three: user, pass, domain.
There is currently no support for replication of only single databases. For the time being, you'll have to set that up manually.
Halts all operations on a MySQL master in preparation for a clean replication shutdown. This is really only useful if your replication status is ``healthy''. If your master is happy and slaves are all replicating, this will work quite well and do the following:
1. commit log writes to disk 2. lock the mysql tables 3. get the mysql master status 4. wait until each slave is synced up 5. shut down the MySQL master
At that point, you can do whatever you wish: promote a slave to master, create an archive of the database directory for syncing to a new slave, or whatever.
$repl->master_halt($dbh, $drh, $vals);
$dbh is a database handle.
$vals is a hashref of values including:
Get and print the MySQL replication master information.
$repl->master_info($dbh, $drh, $vals);
Purges the MySQL replication master binary logs. By default, it saves the last two logs files so that latent slaves don't get the rug yanked out from under them.
$repl->master_purge($dbh, $vals);
Purges all the MySQL replication binlogs, regardless of slave status. This WILL BREAK YOUR REPLICATION. However, sometimes you don't care if you do so, like when your replication processes have already croaked for some reason or another.
$repl->master_purge_force($dbh, $vals);
Purges all but the last two replication binlogs. This method (unlike master_purge above) has no clue about the slaves or their status and merely pulls a list of all binlogs and purges all but the last two. This is potentially dangerous and could break your replication.
$repl->master_purge_old($dbh);
Resets a replication master, purging all binlogs in the process. Use with care.
$repl->master_reset($dbh);
Fetches a list of binlogs from a MySQL replication master.
$list = $repl->master_logs($dbh);
returns an array ref.
Prints out a list of the master replication logs.
$repl->master_logs_show($dbh);
Prints out a MySQL replications master status.
$repl->master_status($dbh);
Prints out information about a MySQL replications slaves status, relative to that of the master.
$repl->slaves_info($db_slaves, $ver_m, $dbh_m);
$repl->slaves_reset($db_sv, $ver);
This function simply shuts down each of your slaves.
Matt Simerson <matt@tnpi.biz>
None known. Report any to author.
The following are all man/perldoc pages:
Copyright (c) 2003-2004, The Network People, Inc. All Rights Reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the The Network People, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.