<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Leakon &#187; Manual</title>
	<atom:link href="http://www.leakon.com/archives/category/manual/feed" rel="self" type="application/rss+xml" />
	<link>http://www.leakon.com</link>
	<description>勤奋 - 创新 - 矢志不渝 - 锲而不舍</description>
	<lastBuildDate>Mon, 06 Feb 2012 02:43:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MySQL bin-log PURGE 清除日志</title>
		<link>http://www.leakon.com/archives/160?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-bin-log-purge-%25e6%25b8%2585%25e9%2599%25a4%25e6%2597%25a5%25e5%25bf%2597</link>
		<comments>http://www.leakon.com/archives/160#comments</comments>
		<pubDate>Wed, 09 Jul 2008 03:16:44 +0000</pubDate>
		<dc:creator>leakon</dc:creator>
				<category><![CDATA[Manual]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[bin-log]]></category>
		<category><![CDATA[PURGE]]></category>

		<guid isPermaLink="false">http://www.leakon.com/?p=160</guid>
		<description><![CDATA[我有一个每天进行大量数据更新的程序，写数据库，用的是innoDB，而且开了bin-log，这段时间，写了几百G的日志，太大了，前一段时间设置过 expire-logs-days =3，但没有生效，不知为什么。
后来实在受不了，上网找了找，原来有另一个方法清除bin-log，且看中文版：
PURGE {MASTER &#124; BINARY} LOGS TO &#8216;log_name&#8217;
PURGE {MASTER &#124; BINARY} LOGS BEFORE  [...]]]></description>
			<content:encoded><![CDATA[<p>我有一个每天进行大量数据更新的程序，写数据库，用的是innoDB，而且开了bin-log，这段时间，写了几百G的日志，太大了，前一段时间设置过 expire-logs-days =3，但没有生效，不知为什么。</p>
<p>后来实在受不了，上网找了找，原来有另一个方法清除bin-log，且看中文版：</p>
<p>PURGE {MASTER | BINARY} LOGS TO &#8216;log_name&#8217;</p>
<p>PURGE {MASTER | BINARY} LOGS BEFORE &#8216;date&#8217;</p>
<p>用于删除列于在指定的日志或日期之前的日志索引中的所有二进制日志。这些日志也会从记录在日志索引文件中的清单中被删除，这样被给定的日志成为第一个。</p>
<p>例如：</p>
<p>PURGE MASTER LOGS TO &#8216;mysql-bin.010&#8242;;</p>
<p>PURGE MASTER LOGS BEFORE &#8217;2008-06-22 13:00:00&#8242;;</p>
<p>清除3天前的 binlog</p>
<p>PURGE MASTER LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 3 DAY);</p>
<p>BEFORE变量的date自变量可以为&#8217;YYYY-MM-DD hh:mm:ss&#8217;格式。MASTER和BINARY是同义词。</p>
<p>如果您有一个活性的从属服务器，该服务器当前正在读取您正在试图删除的日志之一，则本语句不会起作用，而是会失败，并伴随一个错误。不过，如果从属服务器是休止的，并且您碰巧清理了其想要读取的日志之一，则从属服务器启动后不能复制。当从属服务器正在复制时，本语句可以安全运行。您不需要停止它们。</p>
<p>要清理日志，需按照以下步骤：</p>
<p>1. 在每个从属服务器上，使用SHOW SLAVE STATUS来检查它正在读取哪个日志。</p>
<p>2. 使用SHOW MASTER LOGS获得主服务器上的一系列日志。</p>
<p>3. 在所有的从属服务器中判定最早的日志。这个是目标日志。如果所有的从属服务器是更新的，这是清单上的最后一个日志。</p>
<p>4. 制作您将要删除的所有日志的备份。（这个步骤是自选的，但是建议采用。）</p>
<p>5. 清理所有的日志，但是不包括目标日志</p>
<p>本文来自: (www.91linux.com) 详细出处参考：http://www.91linux.com/html/article/database/mysql/20080622/12727.html</p>
<p>以下是MySQL手册的英文原版：</p>
<div class="titlepage">
<div>
<div>
<h4 class="title"><a name="purge-master-logs"></a>13.6.1.1. <code class="literal">PURGE MASTER LOGS</code> Syntax</h4>
</div>
</div>
</div>
<p><a name="id841752"></a></p>
<pre class="programlisting">PURGE {MASTER | BINARY} LOGS TO '<em class="replaceable"><code>log_name</code></em>'
PURGE {MASTER | BINARY} LOGS BEFORE '<em class="replaceable"><code>date</code></em>'
</pre>
<p>Deletes all the binary logs listed in the log index prior to the specified  log or date. The logs also are removed from the list recorded in the log index  file, so that the given log becomes the first.</p>
<p>Example:</p>
<pre class="programlisting">PURGE MASTER LOGS TO 'mysql-bin.010';
PURGE MASTER LOGS BEFORE '2003-04-02 22:46:26';
</pre>
<p>The <code class="literal">BEFORE</code> variant&#8217;s <em class="replaceable"><code>date</code></em> argument can be in <code class="literal">'YYYY-MM-DD hh:mm:ss'</code> format. <code class="literal">MASTER</code> and <code class="literal">BINARY</code> are synonyms.</p>
<p>This statement is safe to run while slaves are replicating. You do not need  to stop them. If you have an active slave that currently is reading one of the  logs you are trying to delete, this statement does nothing and fails with an  error. However, if a slave is dormant and you happen to purge one of the logs it  has yet to read, the slave will be unable to replicate after it comes up.</p>
<p>To safely purge logs, follow this procedure:</p>
<div class="orderedlist">
<ol type="1">
<li>On each slave server, use <code class="literal">SHOW SLAVE STATUS</code> to  check which log it is reading.</li>
<li>Obtain a listing of the binary logs on the master server with <code class="literal">SHOW BINARY LOGS</code>.</li>
<li>Determine the earliest log among all the slaves. This is the target log. If  all the slaves are up to date, this is the last log on the list.</li>
<li>Make a backup of all the logs you are about to delete. (This step is  optional, but always advisable.)</li>
<li>Purge all logs up to but not including the target log.</li>
</ol>
</div>
<p>You can also set the <code class="literal">expire_logs_days</code> system  variable to expire binary log files automatically after a given number of days  (see Section 5.2.3, “System  Variables”). If you are using replication, you should set the variable no  lower than the maximum number of days your slaves might lag behind the master.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leakon.com/archives/160/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

