<?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>Hostmedic &#187; replication</title>
	<atom:link href="http://www.hostmedic.com/tag/replication/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hostmedic.com</link>
	<description>Emergency Medicine for Hosting &#38; Server Admins</description>
	<lastBuildDate>Sun, 12 May 2013 17:57:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Master &#8211; Slave Replication</title>
		<link>http://www.hostmedic.com/admin/systems-administration/database_administration/master-slave-replication/</link>
		<comments>http://www.hostmedic.com/admin/systems-administration/database_administration/master-slave-replication/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 01:51:20 +0000</pubDate>
		<dc:creator>Glenn Kelley</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[citrt]]></category>
		<category><![CDATA[debugging mysql]]></category>
		<category><![CDATA[master]]></category>
		<category><![CDATA[master-slave]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[slave]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[typo3 tuning]]></category>
		<category><![CDATA[Web 2.0 minus or plus]]></category>

		<guid isPermaLink="false">http://churchmedic.com/?p=379</guid>
		<description><![CDATA[There are many reasons to use master-slave replication including but not limited to: 1) Offload some of the queries from one server to another thus helping spread the load: One of the biggest advantages to have master-slave set up in MySQL is to be able to use master for all of the inserts and send [...]]]></description>
				<content:encoded><![CDATA[<p>There are many reasons to use master-slave replication including but not limited to:</p>
<p>1) Offload some of the queries from one server to another thus helping spread the load: One of the biggest advantages to have master-slave set up in MySQL is to be able to use master for all of the inserts and send some, if not all, select queries to a slave (or even a series of slaves). This will most probably speed up your application without having to diving into optimizing all the queries or buying more hardware-  This is especially handy if your using some off the shelf application such as <a href="http://www.webempoweredchurch.com">WebEmpoweredChurch.com</a> / <a href="http://www.typo3usa.com">Typo3</a>,  Magento , WordPress, Drupal, etc . . .</p>
<p>2) Backups can hurt a DB server @ times.   Here @ Typo3USA &#8211; We always Do backups from slave.  Most techs simply just overlook this simple but highly effective advantage.   We have some databases that are quite large &#8211; super large and others that are just a few megs &#8211; to a few gigs.   Sadly &#8211; when the size of a database becomes a big deal is when it has grown to multiple gigs and mysqldump causes the site to lag when it locks tables.  For some sites, this could mean that site goes down for few secs to minutes. If you have slave, you just take slave out of rotation (we have built this into our backup scripts now) and run backups off the slave. You can even stop slave MySQL instance and copy the /etc/mysql/mysql or /var/lib/mysql  (or whatever your database directory ) folder instead of doing mysqldump&#8230;</p>
<p>Recently &#8211; we moved forward into using the <a href="http://www.r1soft.com" target="_blank">R1Soft.com Backup System</a> (in fact we also had a good hand with the Vine Staff and Ron Hall in building up their new website &#8211; check it out @ www.R1soft.com ) WE ABSOLUTELY LOVE THIS SYSTEM BECAUSE IT IS SO FAST IN ITS BACKUPS FOR MYSQL</p>
<p>Ok let us dive into how to setup master-slave replication under MySQL. There are many configuration changes you can do to optimize your MySQL set up. I will just touch on very basic ones to get the replication to work. Here are some assumptions:</p>
<blockquote><p>Master server ip:  10.100.1.1<br />
Slave server ip:  10.100.1.2<br />
Slave username:  slavemysqluser<br />
Slave pw:  slavepw<br />
Your data directory is:  /usr/local/mysql/var/</p></blockquote>
<p>Put the following in your master my.cnf file under [mysqld] section:</p>
<p style="padding-left: 30px;"><code># changes made to do master<br />
server-id           = 1<br />
relay-log           = /usr/local/mysql/var/mysql-relay-bin<br />
relay-log-index     = /usr/local/mysql/var/mysql-relay-bin.index<br />
log-error           = /usr/local/mysql/var/mysql.err<br />
master-info-file    = /usr/local/mysql/var/mysql-master.info<br />
relay-log-info-file = /usr/local/mysql/var/mysql-relay-log.info<br />
datadir             = /usr/local/mysql/var<br />
log-bin             = /usr/local/mysql/var/mysql-bin<br />
# end master</code></p>
<p>Copy the following to slave’s my.cnf under [mysqld] section:</p>
<p style="padding-left: 30px;"><code># changes made to do slave<br />
server-id           = 2<br />
relay-log           = /usr/local/mysql/var/mysql-relay-bin<br />
relay-log-index     = /usr/local/mysql/var/mysql-relay-bin.index<br />
log-error           = /usr/local/mysql/var/mysql.err<br />
master-info-file    = /usr/local/mysql/var/mysql-master.info<br />
relay-log-info-file = /usr/local/mysql/var/mysql-relay-log.info<br />
datadir             = /usr/local/mysql/var<br />
# end slave setup</code></p>
<p style="padding-left: 30px;">Create user on master:<br />
<code>mysql&gt; grant replication slave on *.* to slavemysqluser@'10.100.1.2' identified by 'slavepw';</code></p>
<p style="padding-left: 30px;">Do a dump of data to move to slave<br />
<code>mysqldump -u root --all-databases --single-transaction --master-data=1 &gt; masterdump.sql</code></p>
<p style="padding-left: 30px;">import dump on slave<br />
<code>mysql &lt; masterdump.sql</code></p>
<p style="padding-left: 30px;">After dump is imported go in to mysql client by typing mysql. Let us tell the slave which master to connect to and what login/password to use:<br />
<code>mysql&gt; CHANGE MASTER TO MASTER_HOST='10.100.1.1',  MASTER_USER='slaveuser', MASTER_PASSWORD='slavepw';</code></p>
<p style="padding-left: 30px;">Let us start the slave:<br />
<code>mysql&gt; start slave;</code></p>
<p style="padding-left: 30px;">You can check the status of the slave by typing<br />
<code>mysql&gt; show slave status\G</code></p>
<p>The last command will let you know how up to date the slave is from the master in seconds.  I have had many folks worry about this being behind the master &#8211; it is okay if it does not say ZERO right away &#8211; if you check it you should see the number going down over time until it finally catchs up with the master.</p>
<p>NOTE* if it shows NULL, &#8211; it could be that the slave has not started or that it has an error:  (if this is the case it should show up in Last_errno; and Last_error under the: show slave status\G )</p>
<p>We suggest a number of different tools as well for MySQL including:</p>
<p><strong>Maatkit</strong><br />
<a href="http://www.maatkit.org/">Maatkit</a> is a great set of tools for MySQL Performance Analyses and maintainence.  Must know and have for any MySQL User.</p>
<p><strong>mysqladmin </strong><br />
<em>mysqladmin extended -i100 -r</em> is very nice way to look how MySQL performance counters increment and it can tell you a lot about server run status.</p>
<p><strong>mysqlreport</strong><br />
<a href="http://hackmysql.com/mysqlreport">MySQL Report</a> is a tool which would look at status variables same as <em>mysqladmin extended</em> but will group them together nicely and provide some hints on what are good and bad values.</p>
<p><strong>mysqlsla</strong><br />
This is nice tool to analyze slow query log. It reads bunch of different log formats and has various stats, and it was there before <em>mk-log-parser </em> appeared.</p>
<p><strong>innotop </strong><br />
<a href="http://sourceforge.net/projects/innotop">Innotop</a> is great top like tool for MySQL and is helpful even if you do not use Innodb tables. Very nice to watch what happens to server in the real time.</p>
<p><strong>oprofile</strong><br />
<a href="http://oprofile.sourceforge.net/about/">oprofile</a> is usually used for advanced MySQL tuning when the load is CPU bound – it will tell you where exactly inside MySQL or Kernel CPU time is spent.</p>
<p><strong>iohist</strong><br />
<a href="http://jcole.us/software/iohist/iohist.pl">iohist</a> is a little tool to show histogram for IO response time. The main use for it is to see how response time is split for read and write request rather than seeing the average reported by iostat. These can be very different.</p>
<p><strong>sysbench</strong><br />
<a href="http://sysbench.sf.net/">sysbench</a> is a tool to check performance of system and MySQL. Helpful to check different hardware and OS characteristic.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hostmedic.com/admin/systems-administration/database_administration/master-slave-replication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
