<?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>Linux for Fun &#187; MySQL</title>
	<atom:link href="http://linuxforfun.net/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://linuxforfun.net</link>
	<description>Just for Fun</description>
	<lastBuildDate>Tue, 15 Sep 2009 00:12:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>MySQL live backup using replication</title>
		<link>http://linuxforfun.net/2008/01/07/mysql-live-backup/</link>
		<comments>http://linuxforfun.net/2008/01/07/mysql-live-backup/#comments</comments>
		<pubDate>Mon, 07 Jan 2008 09:09:59 +0000</pubDate>
		<dc:creator>sandajian</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://linuxforfun.net/2008/01/07/mysql-live-backup-using-replication/</guid>
		<description><![CDATA[Assume that you have a website using MySQL as its database. You want to make a live backup of your database on another machine, so that if your host machine encounters a hardware failure, you can recover your web service ASAP. MySQL replication provides a simple way to do that. First, you should prepare your [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "MySQL live backup using replication", url: "http://linuxforfun.net/2008/01/07/mysql-live-backup/" });</script>]]></description>
			<content:encoded><![CDATA[<p>Assume that you have a website using MySQL as its database. You want to make a live backup of your database on another machine, so that if your host machine encounters a hardware failure, you can recover your web service ASAP. MySQL replication provides a simple way to do that.</p>
<p>First, you should prepare your backup machine:</p>
<ul>
<li>it is &#8216;closed&#8217; to your host machine, in the meaning that data transfer speed is fast between them.</li>
<li>it is installed MySQL, the major version should be the same as MySQL on the host machine, ie, both are MySQL 5.x.x, or both are MySQL 4.x.x.</li>
</ul>
<p>Assume that your host machine&#8217;s IP is 192.168.1.111, your backup machine&#8217;s IP is 192.168.2.222.</p>
<p><span id="more-9"></span><br />
<strong>On the host machine:</strong></p>
<p>add the following lines to &#8216;[mysqld]&#8216; section of your my.cnf:</p>
<blockquote><p>server-id=1<br />
log-bin=mysql-bin<br />
binlog-do-db=myblog</p></blockquote>
<p>If you want the host machine as the replication of the backup machine too, add the following lines in my.cnf:</p>
<blockquote><p>master-host=192.168.2.222<br />
master-user=backup<br />
master-password=backup<br />
master-port=3306<br />
master-connect-retry=10<br />
replicate-do-db=myblog<br />
relay-log=relay-bin</p>
<p># important: in multi-master replication,<br />
# add the following 2 lines to avoid conflicting `AUTO_INCREMENT&#8217; values<br />
auto_increment_increment=2<br />
auto_increment_offset=1</p></blockquote>
<p>Note: &#8216;binlog-do-db&#8217; and &#8216;replicate-do-db&#8217; specify the database you want to replicate. If you want to replicate multiple databases, just write multiple lines, one database per line.</p>
<p>Add an account on your MySQL server:</p>
<blockquote><p>GRANT FILE,REPLICATION SLAVE,REPLICATION CLIENT,SUPER ON *.* TO backup@&#8217;192.168.2.222&#8242; IDENTIFIED by &#8216;backup&#8217;;</p></blockquote>
<p><strong>On the backup machine:</strong></p>
<p>add the following lines to &#8216;[mysqld]&#8216; section of your my.cnf:</p>
<blockquote><p>server-id=2<br />
master-host=192.168.1.111<br />
master-user=backup<br />
master-password=backup<br />
master-port=3306<br />
master-connect-retry=10<br />
replicate-do-db=myblog<br />
relay-log=relay-bin</p></blockquote>
<p>If you want dual-direction backup, add the following lines to my.cnf:</p>
<blockquote><p>log-bin=mysql-bin<br />
binlog-do-db=myblog</p>
<p># important: in multi-master replication,<br />
# add the following 2 lines to avoid conflicting `AUTO_INCREMENT&#8217; values<br />
auto_increment_increment=2<br />
auto_increment_offset=2</p></blockquote>
<p>Add an account on your MySQL server:</p>
<blockquote><p>GRANT FILE,REPLICATION SLAVE,REPLICATION CLIENT,SUPER ON *.* TO backup@&#8217;192.168.1.111&#8242; IDENTIFIED by &#8216;backup&#8217;;</p></blockquote>
<p>Now, shutdown MySQL servers on both machines. Copy all databases you need to replicate from the host machine to the backup machine. Then startup MySQL servers on both machines. Examine your mysqld.log for possible errors. Test the replication using some simple SQLs, for example, create a simple table.</p>
<p><a href="http://sharethis.com/item?&wp=3.0.1&amp;publisher=0528fcb2-917b-4b68-8e53-491409263a87&amp;title=MySQL+live+backup+using+replication&amp;url=http%3A%2F%2Flinuxforfun.net%2F2008%2F01%2F07%2Fmysql-live-backup%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://linuxforfun.net/2008/01/07/mysql-live-backup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
