Your company here — click to reach over 10,000 unique daily visitors

mk-purge-logs.1p - Man Page

Purge binary logs on a master based on purge rules.


Usage: mk-purge-logs [OPTION...] DSN

mk-purge-logs purges binary logs on a MySQL server, based on purge rules.

Print and purge all unused binary logs on master:

  mk-purge-logs --print --purge h=master

Silently purge oldest binary logs on master until their total size is less than 1M:

  mk-purge-logs --purge-rules total_size --total-size 1M h=master

Purge oldest, unused binary logs on master until their total size is less than 500k, print information about work done:

  mk-purge-logs --purge-rules unused,total_size --total-size 500k \
    --verbose h=master


The following section is included to inform users about the potential risks, whether known or unknown, of using this tool.  The two main categories of risks are those created by the nature of the tool (e.g. read-only tools vs. read-write tools) and those created by bugs.

mk-purge-logs purges (deletes) binary logs on a master based on "--purge-rules" when "--purge" is specified.  Specifying the wrong "--purge-rules" could delete binary logs that are still needed.

At the time of this release, we know of no bugs that could cause serious harm to users.

The authoritative source for updated information is always the online issue tracking system.  Issues that affect this tool will be marked as such.  You can see a list of such issues at the following URL: <http://www.maatkit.org/bugs/mk-purge-logs>.

See also "Bugs" for more information on filing bugs and getting help.


mk-purge-logs purges binary logs on a master based on "--purge-rules" by executing PURGE BINARY LOGS TO.


Specify at least one of "--purge" or "--print".

This tool accepts additional command-line arguments.  Refer to the "Synopsis" and usage information for details.


group: Connection

Prompt for a password when connecting to MySQL.


type: Array

Read this comma-separated list of config files; if specified, this must be the first option on the command line.


short form: -F; type: string; group: Connection

Only read mysql options from the given file.  You must give an absolute pathname.


Print but do not execute the "--purge" statement (disables "--purge").

Specifying this option allows you to test what mk-purge-logs would do if "--purge" were specified without "--dry-run".  The SQL statement for "--purge" is printed to STDOUT, like:

  This is a dry-run.  The following SQL statement would be executed
  by specifying --purge without --dry-run:
  PURGE BINARY LOGS TO ? mysql-bin.000003

The first line lets you know that "--dry-run" is in effect and the line after it is the SQL statement that would be executed on the server with the ? replaced by the binary log file name that follows it.

See also "--print".


Show help and exit.


short form: -p; type: string; group: Connection

Password to use when connecting.


short form: -P; type: int; group: Connection

Port number to use for connection.


Print which binary logs "--purge" will purge.

This option prints each binary log file name and its size to STDOUT that would be purged if all the "--purge-rules" pass and "--purge" is specified.  Purging uses the MySQL PURGE BINARY LOGS TO command which only specifies the binary log file name to purge to, not the binary logs before it.  This option will print the binary logs before the purge to binary log.

See also "--dry-run".


Purge (delete) binary logs that match all "--purge-rules".  The server's master binary logs are purged using PURGE BINARY LOGS when this option is specified and all "--purge-rules" pass.  Else, no binary logs are purged.

Specify "--print" to see which binary logs are purged and their sizes, else all binary logs are purged silently unless there is an error.

See also "--dry-run".


type: Hash; default: unused

Match binary logs that pass all of the specified rules.  The rules are mutually inclusive, so only binary logs that pass all rules are purged.

Some rules, like total_size, require an extra option to specify their value.

  • total_size

    Purge oldest binary logs until the total size of all binary logs is less than "--total-size".  SHOW BINARY LOGS lists the size of each binary log. If the total of these sizes is greater than "--total-size", then the oldest binary logs are purged until the total size is less than or equal to "--total-size".

  • unused

    Purge binary logs that are no longer being read by any slaves.  When this rule is specified, mk-purge-logs will recurse to the server's first-level slaves (i.e. only direct slaves of the server) and SHOW SLAVE STATUS to find which master binary logs they are reading.  Master binary logs not being read by any slaves are unused and will be purged.


type: string

Preferred recursion method for discovering slaves.

Possible methods are:

  ===========  ================
  processlist  SHOW PROCESSLIST
  hosts        SHOW SLAVE HOSTS

The processlist method is preferred because SHOW SLAVE HOSTS is not reliable. However, the hosts method is required if the server uses a non-standard port (not 3306).  Usually mk-purge-logs does the right thing and finds the slaves, but you may give a preferred method and it will be used first. If it doesn't find any slaves, the other methods will be tried.


type: string; default: wait_timeout=10000; group: Connection

Set these MySQL variables.  Immediately after connecting to MySQL, this string will be appended to SET and executed.


short form: -S; type: string; group: Connection

Socket file to use for connection.


type: size

Purge oldest binary logs until their total size is less than this amount.

This option specifies the value for the "--purge-rules" total_size value.


short form: -u; type: string; group: Connection

User for login if not current user.


short form: -v; default: 0

Print information about binary logs found and purged.  By default mk-purge-logs operates silently, except for errors which are printed to STDERR.  Specifying this option prints extra information to STDOUT about what the tool is doing.


Show version and exit.

DSN Options

These DSN options are used to create a DSN.  Each option is given like option=value.  The options are case-sensitive, so P and p are not the same option.  There cannot be whitespace before or after the = and if the value contains whitespace it must be quoted.  DSN options are comma-separated.  See the maatkit manpage for full details.


You can download Maatkit from Google Code at <http://code.google.com/p/maatkit/>, or you can get any of the tools easily with a command like the following:

   wget http://www.maatkit.org/get/toolname
   wget http://www.maatkit.org/trunk/toolname

Where toolname can be replaced with the name (or fragment of a name) of any of the Maatkit tools.  Once downloaded, they're ready to run; no installation is needed.  The first URL gets the latest released version of the tool, and the second gets the latest trunk code from Subversion.


The environment variable MKDEBUG enables verbose debugging output in all of the Maatkit tools:

   MKDEBUG=1 mk-....

System Requirements

You need Perl, DBI, DBD::mysql, and some core packages that ought to be installed in any reasonably new version of Perl.


For a list of known bugs see <http://www.maatkit.org/bugs/mk-purge-logs>.

Please use Google Code Issues and Groups to report bugs or request support: <http://code.google.com/p/maatkit/>.  You can also join #maatkit on Freenode to discuss Maatkit.

Please include the complete command-line used to reproduce the problem you are seeing, the version of all MySQL servers involved, the complete output of the tool when run with "--version", and if possible, debugging output produced by running with the MKDEBUG=1 environment variable.

Copyright, License and Warranty

This program is copyright 2010-2011 Percona Inc. Feedback and improvements are welcome.


This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2; OR the Perl Artistic License.  On UNIX and similar systems, you can issue `man perlgpl' or `man perlartistic' to read these licenses.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.


Daniel Nichter, Baron Schwartz

About Maatkit

This tool is part of Maatkit, a toolkit for power users of MySQL.  Maatkit was created by Baron Schwartz; Baron and Daniel Nichter are the primary code contributors.  Both are employed by Percona.  Financial support for Maatkit development is primarily provided by Percona and its clients.


This manual page documents Ver 0.9.0 Distrib 7540 $Revision: 7531 $.


2024-01-25 perl v5.38.2 User Contributed Perl Documentation