<?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; upgrade</title> <atom:link href="http://pento.net/tag/upgrade/feed/" rel="self" type="application/rss+xml" /><link>http://pento.net</link> <description>I&#039;m on the Internet</description> <lastBuildDate>Sat, 03 Dec 2011 09:27:46 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.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</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> <span style="color: #993333; font-weight: bold;">START</span> 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> </channel> </rss>
