<?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>Gary Pendergast &#187; replication</title>
	<atom:link href="http://pento.net/tag/replication/feed/" rel="self" type="application/rss+xml" />
	<link>http://pento.net</link>
	<description>I&#039;m on the Internet</description>
	<lastBuildDate>Wed, 08 Sep 2010 07:04:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<cloud domain='pento.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Upgrading MySQL with minimal downtime through Replication</title>
		<link>http://pento.net/2009/02/24/upgrading-mysql-with-minimal-downtime-through-replication/</link>
		<comments>http://pento.net/2009/02/24/upgrading-mysql-with-minimal-downtime-through-replication/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 03:22:17 +0000</pubDate>
		<dc:creator>Gary Pendergast</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL 5.1]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[upgrade]]></category>
		<guid isPermaLink="false">http://pento.net/?p=96</guid>
		<description><![CDATA[Problem With the release of MySQL 5.1, many DBAs are going to be scheduling downtime to upgrade their MySQL Server. As with all upgrades between major version numbers, it requires one of two upgrade paths: Dump/reload: The safest method of upgrading, but it takes out your server for quite some time, especially if you have [...]]]></description>
			<content:encoded><![CDATA[<h2>Problem</h2>
<p>With the release of MySQL 5.1, many DBAs are going to be scheduling downtime to upgrade their MySQL Server. As with all upgrades between major version numbers, it requires one of two upgrade paths:</p>
<ul>
<li>Dump/reload: The safest method of upgrading, but it takes out your server for quite some time, especially if you have a large data set.</li>
<li>mysql_upgrade: A much faster method, but it can still be slow for very large data sets.</li>
</ul>
<p>I&#8217;m here to present a third option. It requires minimal application downtime, and is reasonably simple to prepare for and perform.</p>
<h2>Preparation</h2>
<p>First of all, you&#8217;re going to need a second server (which I&#8217;ll refer to as S2). It will act as a &#8216;stand-in&#8217;, while the main server (which I&#8217;ll refer to as S1) is upgraded. Once S2 is ready to go, you can begin the preparation:</p>
<ul>
<li>If you haven&#8217;t already, enable <a title="MySQL 5.0 Reference Manual: The Binary Log" href="http://dev.mysql.com/doc/refman/5.0/en/binary-log.html">Binary Logging</a> on S1. We will need it to act as a replication Master.</li>
<li>Add an extra bit of functionality to your backup procedure. You will need to store the Binary Log position from when the backup was taken.
<ul>
<li>If you&#8217;re using mysqldump, simply add the &#8211;master-data option to your mysqldump call.</li>
<li>If you&#8217;re using InnoDB Hot Backup, there&#8217;s no need to make a change.  The Binary Log position is shown when you restore the backup.</li>
<li>For other backup methods, you will probably need to get the Binary Log position manually:
<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">FLUSH</span> <span style="color: #993333; font-weight: bold;">TABLES</span> <span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #993333; font-weight: bold;">READ</span> <span style="color: #993333; font-weight: bold;">LOCK</span>;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SHOW</span> MASTER <span style="color: #993333; font-weight: bold;">STATUS</span>;
<span style="color: #66cc66;">&#40;</span>Perform backup now<span style="color: #66cc66;">...</span><span style="color: #66cc66;">&#41;</span>
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">UNLOCK</span> <span style="color: #993333; font-weight: bold;">TABLES</span>;</pre></div></div>
</li>
</ul>
<p>Once you have a backup with the corresponding Binary Log position, you can setup S2:</p>
<ul>
<li>Install MySQL 5.1 on S2.</li>
<li>Restore the backup from S1 to S2.</li>
<li><a title="MySQL 5.1 Reference Manual: Creating a User for Replication" href="http://dev.mysql.com/doc/refman/5.1/en/replication-howto-repuser.html">Create the Slave user on S1</a>.</li>
<li>Enter the Slave settings on S2. You should familiarise yourself with the <a title="MySQL 5.1 Reference Manual: How to Set Up Replication" href="http://dev.mysql.com/doc/refman/5.1/en/replication-howto.html">Replication documentation</a>.</li>
<li>Enable Binary Logging on S2. We&#8217;ll need this during the upgrade process.</li>
<li>Setup S2 as a Slave of S1:
<ul>
<li>If you used mysqldump for the backup, you will need to run the following query:
<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">CHANGE</span> MASTER <span style="color: #993333; font-weight: bold;">TO</span> MASTER_HOST<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'S2.ip.address'</span><span style="color: #66cc66;">,</span> MASTER_USER<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'repl_user'</span><span style="color: #66cc66;">,</span> MASTER_PASSWORD<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'repl_password'</span>;</pre></div></div>
</li>
<li>For any other method, you&#8217;ll need to specify the Binary Log position as well:
<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">CHANGE</span> MASTER <span style="color: #993333; font-weight: bold;">TO</span> MASTER_HOST<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'S2.ip.address'</span><span style="color: #66cc66;">,</span> MASTER_USER<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'repl_user'</span><span style="color: #66cc66;">,</span> MASTER_PASSWORD<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'repl_password'</span><span style="color: #66cc66;">,</span> MASTER_LOG_FILE<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'mysql-bin.nnnnnnn'</span><span style="color: #66cc66;">,</span> MASTER_LOG_POS<span style="color: #66cc66;">=</span>mmmmmmmm;</pre></div></div>
</li>
</ul>
</li>
<li>Start the Slave on S2:
<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> START SLAVE;</pre></div></div>
</li>
</ul>
<p>The major pre-upgrade work is now complete.</p>
<h2>Upgrade</h2>
<p>Just before beginning the upgrade, take a backup of S2. For speed, I&#8217;d recommend running the following queries, then shutting down the MySQL server and copying the data files for the backup.</p>
<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> STOP SLAVE;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SHOW</span> MASTER <span style="color: #993333; font-weight: bold;">STATUS</span>;</pre></div></div>
<p>Once the backup is complete, restart S2 and let it catch up with S1 again.</p>
<p>When you&#8217;re ready to begin the upgrade, you will need a minor outage. Stop your application, and let S2 catch up with S1. Once it has caught up, they will have identical data. So, switch your application to using S2 instead of S1. Your application can continue running unaffected while you upgrade S1 server.</p>
<ul>
<li>Stop the Slave process on S2:
<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> STOP SLAVE;</pre></div></div>
</li>
<li>Stop S1.</li>
<li>Upgrade S1 to MySQL 5.1.</li>
<li>Move the S1 data files to a backup location.</li>
<li>Move the backup from S2 into S1&#8242;s data directory.</li>
<li>Start S2.</li>
<li>Setup S1 as a Slave to S2, same as when we made S2 a Slave of S1.</li>
<li>Let S1 catch up with S2. When it has caught up, stop your application, and make sure S1 is still caught up with S2.</li>
<li>Switch your application back to using S1.</li>
</ul>
<p>Complete! Hooray! You just need to run a couple of queries on S1 to clean up the Slave settings:</p>
<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> STOP SLAVE;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">CHANGE</span> MASTER <span style="color: #993333; font-weight: bold;">TO</span> MASTER_HOST<span style="color: #66cc66;">=</span><span style="color: #ff0000;">''</span>;</pre></div></div>
<h2>Conclusion</h2>
<p>You can keep the outage to only a few minutes while performing this upgrade, removing the need for potentially expensive downtime. If you need the downtime to be zero, you probably want to be looking at a <a title="Advanced MySQL Replication Techniques: Circular Replication" href="http://www.onlamp.com/pub/a/onlamp/2006/04/20/advanced-mysql-replication.html">Circular Replication</a> system, though that&#8217;s getting a little outside of this blog post.</p>
]]></content:encoded>
			<wfw:commentRss>http://pento.net/2009/02/24/upgrading-mysql-with-minimal-downtime-through-replication/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Replication Checksumming Through Encryption</title>
		<link>http://pento.net/2009/02/16/replication-checksumming-through-encryption/</link>
		<comments>http://pento.net/2009/02/16/replication-checksumming-through-encryption/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 22:36:55 +0000</pubDate>
		<dc:creator>Gary Pendergast</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[checksum]]></category>
		<category><![CDATA[corruption]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[SSL]]></category>
		<guid isPermaLink="false">http://pento.net/?p=78</guid>
		<description><![CDATA[Problem A problem we occasionally see is Relay Log corruption, which is most frequently caused by network errors. At this point in time, the replication IO thread does not perform checksumming on incoming data (currently scheduled for MySQL 6.x). In the mean time, we have a relatively easy workaround: encrypt the replication connection. Because of [...]]]></description>
			<content:encoded><![CDATA[<h2>Problem</h2>
<p>A problem we occasionally see is Relay Log corruption, which is most frequently caused by network errors. At this point in time, the replication IO thread does not perform checksumming on incoming data (currently scheduled for <a title="MySQL Worklog #2540: Replication event checksums" href="http://forge.mysql.com/worklog/task.php?id=2540">MySQL 6.x</a>). In the mean time, we have a relatively easy workaround: encrypt the replication connection. Because of the nature of encrypted connections, they have to checksum each packet.</p>
<h2>Solution 1: Replication over SSH Tunnel</h2>
<p>This is the easiest to setup. You simply need to do the following on the Slave:</p>
<pre>shell&gt; ssh -f user@master.server -L 4306:master.server:3306 -N</pre>
<p>This sets up the tunnel. slave.server:4306 is now a tunnelled link to master.server:3306. So now, you just need to alter the Slave to go through the tunnel:</p>
<pre>mysql&gt; STOP SLAVE;
mysql&gt; CHANGE MASTER TO master_host='localhost', master_port=4306;
mysql&gt; START SLAVE;</pre>
<p>Everything else stays the same. Your Slave is still connecting to the same Master, just in a different manner.</p>
<p>This solution does have a couple of downsides, however:</p>
<ul>
<li>If the SSH tunnel goes down, it won&#8217;t automatically reconnect. This can be fixed with a small script that restarts the connection if it fails. The script can be added to your init.d setup, so it automatically opens on server startup.</li>
<li>If you use MySQL Enterprise Monitor, it won&#8217;t be able to recognize that the Master/Slave pair go together.</li>
</ul>
<h2>Solution 2: Replication with SSL</h2>
<p>Replication with SSL can be trickier to setup, but it removes the two downsides of the previous solution. Luckily, the MySQL Documentation Team have done all the hard work for you.</p>
<ul>
<li>Step 1: <a title="MySQL Reference Manual: Setting Up SSL Certificates for MySQL" href="http://dev.mysql.com/doc/refman/en/secure-create-certs.html">Create the certificates</a></li>
<li>Step 2: <a title="MySQL Reference Manual: Using SSL Connections" href="http://dev.mysql.com/doc/refman/en/secure-using-ssl.html">Setup the servers to recognize the certificates</a></li>
<li>Step 3: <a title="MySQL Reference Manual: Setting Up Replication Using SSL" href="http://dev.mysql.com/doc/refman/en/replication-solutions-ssl.html">Change the Slave to use SSL</a></li>
</ul>
<h2>Conclusion</h2>
<p>If you&#8217;re seeing corruption problems in your Relay Log, but not in your Master Binary Log, try Solution 1. It&#8217;s quick to setup and will determine if encryption is the solution to your problem. If it works, setup Solution 2. It will take a little bit of fiddling around, but is certainly worth the effort.</p>
]]></content:encoded>
			<wfw:commentRss>http://pento.net/2009/02/16/replication-checksumming-through-encryption/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Replication with InnoDB and MyISAM Transactions</title>
		<link>http://pento.net/2009/02/13/replication-with-innodb-and-myisam-transactions/</link>
		<comments>http://pento.net/2009/02/13/replication-with-innodb-and-myisam-transactions/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 05:26:57 +0000</pubDate>
		<dc:creator>Gary Pendergast</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL 5.1]]></category>
		<category><![CDATA[RBR]]></category>
		<category><![CDATA[regression]]></category>
		<category><![CDATA[replication]]></category>
		<guid isPermaLink="false">http://pento.net/blog/?p=3</guid>
		<description><![CDATA[There&#8217;s a change of behaviour in MySQL 5.1.31 for Row Based Replication, if you have InnoDB transactions that also write to a MyISAM (or other non-transactional engine) table. It&#8217;s a side effect of fixing Bug #40116. Take this simple example: Transaction 1: INSERT INTO myisam_tbl &#40;item, val&#41; VALUES &#40;1, 0&#41;; Transaction 1: INSERT INTO innodb_tbl [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a change of behaviour in MySQL 5.1.31 for Row Based Replication, if you have InnoDB transactions that also write to a MyISAM (or other non-transactional engine) table. It&#8217;s a side effect of fixing <a title="MySQL Bug #40116: Uncommited changes are replicated and stay on slave after rollback on master" href="http://bugs.mysql.com/40116">Bug #40116</a>. Take this simple example:</p>
<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">Transaction <span style="color: #cc66cc;">1</span>: <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> myisam_tbl <span style="color: #66cc66;">&#40;</span>item<span style="color: #66cc66;">,</span> val<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
Transaction <span style="color: #cc66cc;">1</span>: <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> innodb_tbl <span style="color: #66cc66;">&#40;</span>item<span style="color: #66cc66;">,</span> val<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
Transaction <span style="color: #cc66cc;">1</span>: START TRANSACTION;
Transaction <span style="color: #cc66cc;">1</span>: <span style="color: #993333; font-weight: bold;">UPDATE</span> myisam_tbl <span style="color: #993333; font-weight: bold;">SET</span> val<span style="color: #66cc66;">=</span>val<span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">WHERE</span> item<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span>;
Transaction <span style="color: #cc66cc;">1</span>: <span style="color: #993333; font-weight: bold;">UPDATE</span> innodb_tbl <span style="color: #993333; font-weight: bold;">SET</span> val<span style="color: #66cc66;">=</span><span style="color: #66cc66;">&#40;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> val <span style="color: #993333; font-weight: bold;">FROM</span> myisam_tbl <span style="color: #993333; font-weight: bold;">WHERE</span> item<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">WHERE</span> item<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span>;
Transaction <span style="color: #cc66cc;">2</span>: START TRANSACTION;
Transaction <span style="color: #cc66cc;">2</span>: <span style="color: #993333; font-weight: bold;">UPDATE</span> myisam_tbl <span style="color: #993333; font-weight: bold;">SET</span> val<span style="color: #66cc66;">=</span>val<span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">WHERE</span> item<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span>;
Transaction <span style="color: #cc66cc;">2</span>: <span style="color: #993333; font-weight: bold;">UPDATE</span> innodb_tbl <span style="color: #993333; font-weight: bold;">SET</span> val<span style="color: #66cc66;">=</span><span style="color: #66cc66;">&#40;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> val <span style="color: #993333; font-weight: bold;">FROM</span> myisam_tbl <span style="color: #993333; font-weight: bold;">WHERE</span> item<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">WHERE</span> item<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">2</span>;
Transaction <span style="color: #cc66cc;">2</span>: COMMIT;
Transaction <span style="color: #cc66cc;">1</span>: COMMIT;</pre></div></div>
<p>After this, the Master innodb_tbl would look like this:</p>
<table>
<tbody>
<tr>
<th>item</th>
<th>val</th>
</tr>
<tr>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
</tr>
</tbody>
</table>
<p>And the Master myisam_tbl will look like this:</p>
<table>
<tbody>
<tr>
<th>item</th>
<th>val</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
</tr>
</tbody>
</table>
<p>In 5.1.30 and earlier, the Slave tables will be correct. However, in 5.1.31, the Slave myisam_tbl will be correct, but the innodb_tbl will look like this:</p>
<table>
<tbody>
<tr>
<th>item</th>
<th>val</th>
</tr>
<tr>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>2</td>
<td>1</td>
</tr>
</tbody>
</table>
<p>As a bonus, there&#8217;s no workaround. Statement Based Replication has never worked for this case. For an SBR Slave (In MySQL 5.0.x and 5.1.x), the Slave myisam_tbl will be correct, but the Slave innodb_tbl will look like this:</p>
<table>
<tbody>
<tr>
<th>item</th>
<th>val</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
</tr>
</tbody>
</table>
<p>And so, we come to the moral of the story. Don&#8217;t use non-transactional tables in the middle of a transaction. Ever. You will only cause yourself more pain than you can possibly imagine. Instead, move the writes to the non-transactional tables outside of the transaction.</p>
]]></content:encoded>
			<wfw:commentRss>http://pento.net/2009/02/13/replication-with-innodb-and-myisam-transactions/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
