<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="mysqlbinlog-backup">
      </a>
      6.6.9.3 Using mysqlbinlog to Back Up Binary Log Files
     </h4>
    </div>
   </div>
  </div>
  <p>
   By default,
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   reads binary log
        files and displays their contents in text format. This enables
        you to examine events within the files more easily and to
        re-execute them (for example, by using the output as input to
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   ).
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   can
        read log files directly from the local file system, or, with the
   <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_read-from-remote-server">
    <code class="option">
     --read-from-remote-server
    </code>
   </a>
   option, it can connect to a server and request binary log
        contents from that server.
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   writes
        text output to its standard output, or to the file named as the
        value of the
   <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_result-file">
    <code class="option">
     --result-file=
     <em class="replaceable">
      <code>
       file_name
      </code>
     </em>
    </code>
   </a>
   option if that option is given.
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="xref" href="mysqlbinlog-backup.html#mysqlbinlog-backup-capabilities" title="mysqlbinlog Backup Capabilities">
       mysqlbinlog Backup Capabilities
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="mysqlbinlog-backup.html#mysqlbinlog-backup-options" title="mysqlbinlog Backup Options">
       mysqlbinlog Backup Options
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="mysqlbinlog-backup.html#mysqlbinlog-backup-static-live" title="Static and Live Backups">
       Static and Live Backups
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="mysqlbinlog-backup.html#mysqlbinlog-backup-output-file-naming" title="Output File Naming">
       Output File Naming
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="mysqlbinlog-backup.html#mysqlbinlog-backup-example" title="Example: mysqldump + mysqlbinlog for Backup and Restore">
       Example: mysqldump + mysqlbinlog for Backup and Restore
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="mysqlbinlog-backup.html#mysqlbinlog-backup-restrictions" title="mysqlbinlog Backup Restrictions">
       mysqlbinlog Backup Restrictions
      </a>
     </p>
    </li>
   </ul>
  </div>
  <h5>
   <a name="mysqlbinlog-backup-capabilities">
   </a>
   mysqlbinlog Backup Capabilities
  </h5>
  <p>
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   can read binary log files and
        write new files containing the same content—that is, in
        binary format rather than text format. This capability enables
        you to easily back up a binary log in its original format.
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   can make a static backup, backing
        up a set of log files and stopping when the end of the last file
        is reached. It can also make a continuous (
   <span class="quote">
    “
    <span class="quote">
     live
    </span>
    ”
   </span>
   )
        backup, staying connected to the server when it reaches the end
        of the last log file and continuing to copy new events as they
        are generated. In continuous-backup operation,
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   runs until the connection ends
        (for example, when the server exits) or
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   is forcibly terminated. When the
        connection ends,
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   does not wait
        and retry the connection, unlike a replica server. To continue a
        live backup after the server has been restarted, you must also
        restart
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   .
  </p>
  <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Important
   </div>
   <p>
    <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
     <span class="command">
      <strong>
       mysqlbinlog
      </strong>
     </span>
    </a>
    can back up both encrypted and
          unencrypted binary log files . However, copies of encrypted
          binary log files that are generated using
    <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
     <span class="command">
      <strong>
       mysqlbinlog
      </strong>
     </span>
    </a>
    are stored in an unencrypted
          format.
   </p>
  </div>
  <h5>
   <a name="mysqlbinlog-backup-options">
   </a>
   mysqlbinlog Backup Options
  </h5>
  <p>
   Binary log backup requires that you invoke
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   with two options at minimum:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      The
      <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_read-from-remote-server">
       <code class="option">
        --read-from-remote-server
       </code>
      </a>
      (or
      <code class="option">
       -R
      </code>
      ) option tells
      <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
       <span class="command">
        <strong>
         mysqlbinlog
        </strong>
       </span>
      </a>
      to connect to a server and
            request its binary log. (This is similar to a replica server
            connecting to its replication source server.)
     </p>
    </li>
    <li class="listitem">
     <p>
      The
      <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_raw">
       <code class="option">
        --raw
       </code>
      </a>
      option tells
      <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
       <span class="command">
        <strong>
         mysqlbinlog
        </strong>
       </span>
      </a>
      to write raw (binary) output,
            not text output.
     </p>
    </li>
   </ul>
  </div>
  <p>
   Along with
   <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_read-from-remote-server">
    <code class="option">
     --read-from-remote-server
    </code>
   </a>
   ,
        it is common to specify other options:
   <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_host">
    <code class="option">
     --host
    </code>
   </a>
   indicates where the
        server is running, and you may also need to specify connection
        options such as
   <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_user">
    <code class="option">
     --user
    </code>
   </a>
   and
   <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_password">
    <code class="option">
     --password
    </code>
   </a>
   .
  </p>
  <p>
   Several other options are useful in conjunction with
   <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_raw">
    <code class="option">
     --raw
    </code>
   </a>
   :
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_stop-never">
       <code class="option">
        --stop-never
       </code>
      </a>
      : Stay
            connected to the server after reaching the end of the last
            log file and continue to read new events.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_connection-server-id">
       <code class="option">
        --connection-server-id=
        <em class="replaceable">
         <code>
          id
         </code>
        </em>
       </code>
      </a>
      :
            The server ID that
      <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
       <span class="command">
        <strong>
         mysqlbinlog
        </strong>
       </span>
      </a>
      reports
            when it connects to a server. When
      <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_stop-never">
       <code class="option">
        --stop-never
       </code>
      </a>
      is used,
            the default reported server ID is 1. If this causes a
            conflict with the ID of a replica server or another
      <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
       <span class="command">
        <strong>
         mysqlbinlog
        </strong>
       </span>
      </a>
      process, use
      <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_connection-server-id">
       <code class="option">
        --connection-server-id
       </code>
      </a>
      to specify an alternative server ID. See
      <a class="xref" href="mysqlbinlog-server-id.html" title="6.6.9.4 Specifying the mysqlbinlog Server ID">
       Section 6.6.9.4, “Specifying the mysqlbinlog Server ID”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_result-file">
       <code class="option">
        --result-file
       </code>
      </a>
      : A prefix
            for output file names, as described later.
     </p>
    </li>
   </ul>
  </div>
  <h5>
   <a name="mysqlbinlog-backup-static-live">
   </a>
   Static and Live Backups
  </h5>
  <p>
   To back up a server's binary log files with
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   , you must specify file names that
        actually exist on the server. If you do not know the names,
        connect to the server and use the
   <a class="link" href="show-binary-logs.html" title="15.7.7.2 SHOW BINARY LOGS Statement">
    <code class="literal">
     SHOW
        BINARY LOGS
    </code>
   </a>
   statement to see the current names.
        Suppose that the statement produces this output:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa7187544"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token datatype">BINARY</span> <span class="token keyword">LOGS</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Log_name      <span class="token punctuation">|</span> File_size <span class="token punctuation">|</span> Encrypted <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> binlog.000130 <span class="token punctuation">|</span>     27459 <span class="token punctuation">|</span> No        <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> binlog.000131 <span class="token punctuation">|</span>     13719 <span class="token punctuation">|</span> No        <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> binlog.000132 <span class="token punctuation">|</span>     43268 <span class="token punctuation">|</span> No        <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
  </div>
  <p>
   With that information, you can use
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   to back up the binary log to the
        current directory as follows (enter each command on a single
        line):
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      To make a static backup of
      <code class="filename">
       binlog.000130
      </code>
      through
      <code class="filename">
       binlog.000132
      </code>
      , use either of these
            commands:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa68537448"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">mysqlbinlog <span class="token property">--read-from-remote-server</span> <span class="token constant">--host</span><span class="token attr-value"><span class="token punctuation">=</span><em class="replaceable">host_name</em></span> <span class="token property">--raw</span>
  binlog<span class="token punctuation">.</span>000130 binlog<span class="token punctuation">.</span>000131 binlog<span class="token punctuation">.</span>000132

mysqlbinlog <span class="token property">--read-from-remote-server</span> <span class="token constant">--host</span><span class="token attr-value"><span class="token punctuation">=</span><em class="replaceable">host_name</em></span> <span class="token property">--raw</span>
  <span class="token property">--to-last-log</span> binlog<span class="token punctuation">.</span>000130</code></pre>
     </div>
     <p>
      The first command specifies every file name explicitly. The
            second names only the first file and uses
      <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_to-last-log">
       <code class="option">
        --to-last-log
       </code>
      </a>
      to read
            through the last. A difference between these commands is
            that if the server happens to open
      <code class="filename">
       binlog.000133
      </code>
      before
      <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
       <span class="command">
        <strong>
         mysqlbinlog
        </strong>
       </span>
      </a>
      reaches the end of
      <code class="filename">
       binlog.000132
      </code>
      , the first command does
            not read it, but the second command does.
     </p>
    </li>
    <li class="listitem">
     <p>
      To make a live backup in which
      <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
       <span class="command">
        <strong>
         mysqlbinlog
        </strong>
       </span>
      </a>
      starts with
      <code class="filename">
       binlog.000130
      </code>
      to copy existing log
            files, then stays connected to copy new events as the server
            generates them:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa61316480"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">mysqlbinlog <span class="token property">--read-from-remote-server</span> <span class="token constant">--host</span><span class="token attr-value"><span class="token punctuation">=</span><em class="replaceable">host_name</em></span> <span class="token property">--raw</span>
  <span class="token property">--stop-never</span> binlog<span class="token punctuation">.</span>000130</code></pre>
     </div>
     <p>
      With
      <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_stop-never">
       <code class="option">
        --stop-never
       </code>
      </a>
      , it is
            not necessary to specify
      <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_to-last-log">
       <code class="option">
        --to-last-log
       </code>
      </a>
      to read to
            the last log file because that option is implied.
     </p>
    </li>
   </ul>
  </div>
  <h5>
   <a name="mysqlbinlog-backup-output-file-naming">
   </a>
   Output File Naming
  </h5>
  <p>
   Without
   <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_raw">
    <code class="option">
     --raw
    </code>
   </a>
   ,
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   produces text output and the
   <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_result-file">
    <code class="option">
     --result-file
    </code>
   </a>
   option, if
        given, specifies the name of the single file to which all output
        is written. With
   <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_raw">
    <code class="option">
     --raw
    </code>
   </a>
   ,
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   writes one binary output file for
        each log file transferred from the server. By default,
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   writes the files in the current
        directory with the same names as the original log files. To
        modify the output file names, use the
   <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_result-file">
    <code class="option">
     --result-file
    </code>
   </a>
   option. In
        conjunction with
   <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_raw">
    <code class="option">
     --raw
    </code>
   </a>
   , the
   <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_result-file">
    <code class="option">
     --result-file
    </code>
   </a>
   option value
        is treated as a prefix that modifies the output file names.
  </p>
  <p>
   Suppose that a server currently has binary log files named
   <code class="filename">
    binlog.000999
   </code>
   and up. If you use
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog --raw
     </strong>
    </span>
   </a>
   to back up the files, the
   <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_result-file">
    <code class="option">
     --result-file
    </code>
   </a>
   option
        produces output file names as shown in the following table. You
        can write the files to a specific directory by beginning the
   <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_result-file">
    <code class="option">
     --result-file
    </code>
   </a>
   value with the
        directory path. If the
   <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_result-file">
    <code class="option">
     --result-file
    </code>
   </a>
   value consists
        only of a directory name, the value must end with the pathname
        separator character. Output files are overwritten if they exist.
  </p>
  <div class="informaltable">
   <table summary="mysqlbinlog --result-file options and corresponding output file names, as described in the example in the preceding text.">
    <colgroup>
     <col style="width: 50%"/>
     <col style="width: 50%"/>
    </colgroup>
    <thead>
     <tr>
      <th>
       <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_result-file">
        <code class="option">
         --result-file
        </code>
       </a>
       Option
      </th>
      <th>
       Output File Names
      </th>
     </tr>
    </thead>
    <tbody>
     <tr>
      <td>
       <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_result-file">
        <code class="option">
         --result-file=x
        </code>
       </a>
      </td>
      <td>
       <code class="filename">
        xbinlog.000999
       </code>
       and up
      </td>
     </tr>
     <tr>
      <td>
       <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_result-file">
        <code class="option">
         --result-file=/tmp/
        </code>
       </a>
      </td>
      <td>
       <code class="filename">
        /tmp/binlog.000999
       </code>
       and up
      </td>
     </tr>
     <tr>
      <td>
       <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_result-file">
        <code class="option">
         --result-file=/tmp/x
        </code>
       </a>
      </td>
      <td>
       <code class="filename">
        /tmp/xbinlog.000999
       </code>
       and up
      </td>
     </tr>
    </tbody>
   </table>
  </div>
  <h5>
   <a name="mysqlbinlog-backup-example">
   </a>
   Example: mysqldump + mysqlbinlog for Backup and Restore
  </h5>
  <p>
   The following example describes a simple scenario that shows how
        to use
   <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
    <span class="command">
     <strong>
      mysqldump
     </strong>
    </span>
   </a>
   and
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   together to back up a server's
        data and binary log, and how to use the backup to restore the
        server if data loss occurs. The example assumes that the server
        is running on host
   <em class="replaceable">
    <code>
     host_name
    </code>
   </em>
   and its
        first binary log file is named
   <code class="filename">
    binlog.000999
   </code>
   . Enter each command on a
        single line.
  </p>
  <p>
   Use
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   to make a continuous backup
        of the binary log:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa50150666"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">mysqlbinlog <span class="token property">--read-from-remote-server</span> <span class="token constant">--host</span><span class="token attr-value"><span class="token punctuation">=</span><em class="replaceable">host_name</em></span> <span class="token property">--raw</span>
  <span class="token property">--stop-never</span> binlog<span class="token punctuation">.</span>000999</code></pre>
  </div>
  <p>
   Use
   <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
    <span class="command">
     <strong>
      mysqldump
     </strong>
    </span>
   </a>
   to create a dump file as a
        snapshot of the server's data. Use
   <a class="link" href="mysqldump.html#option_mysqldump_all-databases">
    <code class="option">
     --all-databases
    </code>
   </a>
   ,
   <a class="link" href="mysqldump.html#option_mysqldump_events">
    <code class="option">
     --events
    </code>
   </a>
   , and
   <a class="link" href="mysqldump.html#option_mysqldump_routines">
    <code class="option">
     --routines
    </code>
   </a>
   to back up all
        data, and
   <a class="link" href="mysqldump.html#option_mysqldump_source-data">
    <code class="option">
     --source-data=2
    </code>
   </a>
   to
        include the current binary log coordinates in the dump file.
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa51824947"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">mysqldump <span class="token constant">--host</span><span class="token attr-value"><span class="token punctuation">=</span><em class="replaceable">host_name</em></span> <span class="token property">--all-databases</span> <span class="token property">--events</span> <span class="token property">--routines</span> <span class="token constant">--source-data</span><span class="token attr-value"><span class="token punctuation">=</span>2&gt;</span> <em class="replaceable">dump_file</em></code></pre>
  </div>
  <p>
   Execute the
   <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
    <span class="command">
     <strong>
      mysqldump
     </strong>
    </span>
   </a>
   command periodically to
        create newer snapshots as desired.
  </p>
  <p>
   If data loss occurs (for example, if the server unexpectedly
        exits), use the most recent dump file to restore the data:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa17086222"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">mysql <span class="token constant">--host</span><span class="token attr-value"><span class="token punctuation">=</span><em class="replaceable">host_name</em></span> <span class="token property">-u</span> root <span class="token property">-p</span> &lt; <em class="replaceable">dump_file</em></code></pre>
  </div>
  <p>
   Then use the binary log backup to re-execute events that were
        written after the coordinates listed in the dump file. Suppose
        that the coordinates in the file look like this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa17083675"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-none">-- CHANGE REPLICATION SOURCE TO SOURCE_LOG_FILE='binlog.001002', SOURCE_LOG_POS=27284;</code></pre>
  </div>
  <p>
   If the most recent backed-up log file is named
   <code class="filename">
    binlog.001004
   </code>
   , re-execute the log events
        like this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa89097034"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">mysqlbinlog <span class="token constant">--start-position</span><span class="token attr-value"><span class="token punctuation">=</span>27284</span> binlog<span class="token punctuation">.</span>001002 binlog<span class="token punctuation">.</span>001003 binlog<span class="token punctuation">.</span>001004
  | mysql <span class="token constant">--host</span><span class="token attr-value"><span class="token punctuation">=</span><em class="replaceable">host_name</em></span> <span class="token property">-u</span> root <span class="token property">-p</span></code></pre>
  </div>
  <p>
   You might find it easier to copy the backup files (dump file and
        binary log files) to the server host to make it easier to
        perform the restore operation, or if MySQL does not allow remote
   <code class="literal">
    root
   </code>
   access.
  </p>
  <h5>
   <a name="mysqlbinlog-backup-restrictions">
   </a>
   mysqlbinlog Backup Restrictions
  </h5>
  <p>
   Binary log backups with
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   are
        subject to these restrictions:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
       <span class="command">
        <strong>
         mysqlbinlog
        </strong>
       </span>
      </a>
      does not automatically
            reconnect to the MySQL server if the connection is lost (for
            example, if a server restart occurs or there is a network
            outage).
     </p>
    </li>
    <li class="listitem">
     <p>
      The delay for a backup is similar to the delay for a replica
            server.
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
