<?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>Denie&#039;s Tech Blog &#187; MySQL</title>
	<atom:link href="http://blog.nataprawira.com/tech/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nataprawira.com/tech</link>
	<description>Information Technology for Life!</description>
	<lastBuildDate>Mon, 19 Jul 2010 09:20:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Scripting a MySQL InnoDB Engine Conversion</title>
		<link>http://blog.nataprawira.com/tech/2010/07/11/scripting-a-mysql-innodb-engine-conversion/</link>
		<comments>http://blog.nataprawira.com/tech/2010/07/11/scripting-a-mysql-innodb-engine-conversion/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 19:50:08 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Conversion]]></category>
		<category><![CDATA[InnoDB]]></category>
		<category><![CDATA[MyISAM]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=161</guid>
		<description><![CDATA[

0) Backup your database.
You should probably be doing this already.  Now’s a good time to make sure that your backups ran.
 
1) Create the script.
You’ll need the correct permissions to query the database. Here’s the command.  Be sure to change &#60;DATABASE_NAME&#62; as it fits.
# mysql -p -e "show tables in &#60;DATABASE_NAME&#62;;" &#124; \
tail --lines=+2 &#124; [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F07%2F11%2Fscripting-a-mysql-innodb-engine-conversion%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F07%2F11%2Fscripting-a-mysql-innodb-engine-conversion%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<h3 style="font-family: 'Trebuchet MS', 'Lucida Grande', Verdana, Arial, sans-serif;font-weight: bold;font-size: 1.3em;color: #333333;text-decoration: none;margin-top: 30px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;padding: 0px"><span style="color: #000000;font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;font-weight: normal;font-size: 13px"><strong>0) Backup your database.<br />
</strong>You should probably be doing this already.  Now’s a good time to make sure that your backups ran.</span></h3>
<p><span style="color: #000000;font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;font-weight: normal;font-size: 13px"> </span></p>
<p><strong>1) Create the script.<br />
</strong>You’ll need the correct permissions to query the database. Here’s the command.  Be sure to change &lt;DATABASE_NAME&gt; as it fits.</p>
<p><code style="font: normal normal normal 1.1em/normal 'Courier New', Courier, Fixed"><strong><span style="color: #0000ff"># mysql -p -e "show tables in &lt;DATABASE_NAME&gt;;" | \<br />
tail --lines=+2 | \<br />
xargs -i echo "ALTER TABLE {} ENGINE=INNODB;" &gt; alter_table.sql</span></strong></code></p>
<p><strong>2) Run the script</strong>.</p>
<p><code style="font: normal normal normal 1.1em/normal 'Courier New', Courier, Fixed"><strong><span style="color: #0000ff"># mysql --database=&lt;DATABASE_NAME&gt; -p &lt; alter_table.sql</span></strong></code></p>
<p><strong>3) Verify</strong> it by running this command in mysql:</p>
<p><code style="font: normal normal normal 1.1em/normal 'Courier New', Courier, Fixed"><strong><span style="color: #0000ff">mysql&gt; show table status;</span></strong></code></p>
<p><span id="more-161"></span></p>
<p><strong><a title="http://technotes.twosmallcoins.com/?cat=268" href="http://technotes.twosmallcoins.com/?cat=268" target="_blank">SOURCE</a></strong></p>

<div class="bitly_links">
<div class="bitly_linkstext">
Share this on : 
</div>
<ul>
	<li class="bitly_linksfirst"><a rel="nofollow" id="facebook" target="_blank" href="javascript:window.location='http%3A%2F%2Fwww.facebook.com%2Fshare.php%3Fu%3Dhttp%253A%252F%252Fbit.ly%252F90wNH0%26amp%3Bt%3DScripting%2520a%2520MySQL%2520InnoDB%2520Engine%2520Conversion';" title="Facebook">Facebook</a></li>
	<li><a rel="nofollow" id="friendfeed" target="_blank" href="javascript:window.location='http%3A%2F%2Fwww.friendfeed.com%2Fshare%3Ftitle%3DScripting%2520a%2520MySQL%2520InnoDB%2520Engine%2520Conversion%26amp%3Blink%3Dhttp%253A%252F%252Fbit.ly%252F90wNH0';" title="Friendfeed">Friendfeed</a></li>
	<li><a rel="nofollow" id="posterous" target="_blank" href="javascript:window.location='http%3A%2F%2Fposterous.com%2Fshare%3Flinkto%3Dhttp%253A%252F%252Fbit.ly%252F90wNH0%26amp%3Btitle%3DScripting%2520a%2520MySQL%2520InnoDB%2520Engine%2520Conversion%26amp%3Bselection%3D';" title="Posterous">Posterous</a></li>
	<li><a rel="nofollow" id="tumblr" target="_blank" href="javascript:window.location='http%3A%2F%2Fwww.tumblr.com%2Fshare%3Fv%3D3%26amp%3Bu%3Dhttp%253A%252F%252Fbit.ly%252F90wNH0%26amp%3Bt%3DScripting%2520a%2520MySQL%2520InnoDB%2520Engine%2520Conversion%26amp%3Bs%3D';" title="Tumblr">Tumblr</a></li>
	<li class="bitly_linkslast"><a rel="nofollow" id="twitter" target="_blank" href="javascript:window.location='http%3A%2F%2Ftwitter.com%2Fhome%3Fstatus%3DScripting%2520a%2520MySQL%2520InnoDB%2520Engine%2520Conversion%2520-%2520http%253A%252F%252Fbit.ly%252F90wNH0';" title="Twitter">Twitter</a></li>
</ul>
</div>
<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2010/07/11/scripting-a-mysql-innodb-engine-conversion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simple MySQL Backup with auto 3 days old file deletion</title>
		<link>http://blog.nataprawira.com/tech/2010/07/04/simple-mysql-backup-with-auto-3-days-old-file-deletion/</link>
		<comments>http://blog.nataprawira.com/tech/2010/07/04/simple-mysql-backup-with-auto-3-days-old-file-deletion/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 13:57:27 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Backup]]></category>
		<category><![CDATA[Delete]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=152</guid>
		<description><![CDATA[

/usr/local/bin/mysql.backup.sh

#!/bin/bash
NOW=$(date +"%m-%d-%Y")
OLD=$(date +"%m-%d-%Y" --date="3 days ago")
PROJECT="project_name"
LOCATION="/home/backup"
FILE="$PROJECT.$NOW.sql"
FILE2="$FILE.gz"
FILEOLD="$PROJECT.$OLD.sql.gz"
EMAIL="youremail@domain.com"
$SQLUSER="username"
$SQLPASS="password"
$SQLNAME="database_name"
cd $LOCATION ; \
rm -f $FILEOLD ; \
mysqldump -u $SQLUSER --password=$SQLPASS $SQLNAME &#62; \
$LOCATION/$FILE ; \
gzip $LOCATION/$FILE ; \
echo "Backup location is in $LOCATION/$FILE2" &#124; \
mail -s "[$PROJECT] MySQL Backup" $EMAIL

Then you can put it on your cron (background process)
Below cron will execute the script on Saturday at 12AM:

0 0 [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F07%2F04%2Fsimple-mysql-backup-with-auto-3-days-old-file-deletion%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F07%2F04%2Fsimple-mysql-backup-with-auto-3-days-old-file-deletion%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p><strong>/usr/local/bin/mysql.backup.sh</strong></p>
<blockquote>
<pre><strong><span style="color: #000080">#!/bin/bash
NOW=$(date +"%m-%d-%Y")
OLD=$(date +"%m-%d-%Y" --date="3 days ago")
PROJECT="project_name"
LOCATION="/home/backup"
FILE="$PROJECT.$NOW.sql"
FILE2="$FILE.gz"
FILEOLD="$PROJECT.$OLD.sql.gz"
EMAIL="youremail@domain.com"
$SQLUSER="username"
$SQLPASS="password"
$SQLNAME="database_name"</span></strong></pre>
<pre><strong><span style="color: #000080">cd $LOCATION ; \
rm -f $FILEOLD ; \
mysqldump -u $SQLUSER --password=$SQLPASS $SQLNAME &gt; \
$LOCATION/$FILE ; \
gzip $LOCATION/$FILE ; \
echo "Backup location is in $LOCATION/$FILE2" | \
mail -s "[$PROJECT] MySQL Backup" $EMAIL</span></strong></pre>
</blockquote>
<p>Then you can put it on your cron (background process)</p>
<p>Below cron will execute the script on <strong>Saturday at 12AM</strong>:</p>
<blockquote>
<pre><strong><span style="color: #000080">0 0 * * 6 /usr/local/bin/mysql.backup.sh</span></strong></pre>
</blockquote>
<p>Good luck!</p>

<div class="bitly_links">
<div class="bitly_linkstext">
Share this on : 
</div>
<ul>
	<li class="bitly_linksfirst"><a rel="nofollow" id="facebook" target="_blank" href="javascript:window.location='http%3A%2F%2Fwww.facebook.com%2Fshare.php%3Fu%3Dhttp%253A%252F%252Fbit.ly%252Fd1O3YA%26amp%3Bt%3DSimple%2520MySQL%2520Backup%2520with%2520auto%25203%2520days%2520old%2520file%2520deletion';" title="Facebook">Facebook</a></li>
	<li><a rel="nofollow" id="friendfeed" target="_blank" href="javascript:window.location='http%3A%2F%2Fwww.friendfeed.com%2Fshare%3Ftitle%3DSimple%2520MySQL%2520Backup%2520with%2520auto%25203%2520days%2520old%2520file%2520deletion%26amp%3Blink%3Dhttp%253A%252F%252Fbit.ly%252Fd1O3YA';" title="Friendfeed">Friendfeed</a></li>
	<li><a rel="nofollow" id="posterous" target="_blank" href="javascript:window.location='http%3A%2F%2Fposterous.com%2Fshare%3Flinkto%3Dhttp%253A%252F%252Fbit.ly%252Fd1O3YA%26amp%3Btitle%3DSimple%2520MySQL%2520Backup%2520with%2520auto%25203%2520days%2520old%2520file%2520deletion%26amp%3Bselection%3D';" title="Posterous">Posterous</a></li>
	<li><a rel="nofollow" id="tumblr" target="_blank" href="javascript:window.location='http%3A%2F%2Fwww.tumblr.com%2Fshare%3Fv%3D3%26amp%3Bu%3Dhttp%253A%252F%252Fbit.ly%252Fd1O3YA%26amp%3Bt%3DSimple%2520MySQL%2520Backup%2520with%2520auto%25203%2520days%2520old%2520file%2520deletion%26amp%3Bs%3D';" title="Tumblr">Tumblr</a></li>
	<li class="bitly_linkslast"><a rel="nofollow" id="twitter" target="_blank" href="javascript:window.location='http%3A%2F%2Ftwitter.com%2Fhome%3Fstatus%3DSimple%2520MySQL%2520Backup%2520with%2520auto%25203%2520days%2520old%2520file%2520deletion%2520-%2520http%253A%252F%252Fbit.ly%252Fd1O3YA';" title="Twitter">Twitter</a></li>
</ul>
</div>
<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2010/07/04/simple-mysql-backup-with-auto-3-days-old-file-deletion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to tune Apache and Mysql</title>
		<link>http://blog.nataprawira.com/tech/2009/07/25/how-to-tune-apache-and-mysql/</link>
		<comments>http://blog.nataprawira.com/tech/2009/07/25/how-to-tune-apache-and-mysql/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 17:29:43 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[tune]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=66</guid>
		<description><![CDATA[

By default, Apache comes preconfigured to serve a maximum of 256 clients simultaneously. This particular configuration setting can be found in the file /etc/httpd/conf/httpd.conf
If your server has 2 GB of RAM, and you’re sharing your server with MySQL(true in my case), you’ll want to reserve about half of it for Apache (1 GB)

MaxClients: here is [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F07%2F25%2Fhow-to-tune-apache-and-mysql%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F07%2F25%2Fhow-to-tune-apache-and-mysql%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p>By default, Apache comes preconfigured to serve a maximum of 256 clients simultaneously. This particular configuration setting can be found in the file <strong>/etc/httpd/conf/httpd.conf</strong></p>
<p>If your server has 2 GB of RAM, and you’re sharing your server with MySQL(true in my case), you’ll want to reserve about half of it for Apache (1 GB)</p>
<p><span id="more-66"></span></p>
<p>MaxClients: here is the process of determining MaxClients. type<strong> </strong></p>
<p style="padding-left: 30px"><strong>ps -U apache -u apache u</strong></p>
<p>See the number of apache process running in you command prompt.<strong></strong></p>
<p style="padding-left: 30px"><strong>USER       PID %CPU %MEM    VSZ     RSS  TTY    STAT START   TIME COMMAND<br />
apache     7694     0.0     0.3       42704  6680    ?        S       18:30   0:00 /usr/sbin/httpd</strong></p>
<p>The above indicates that a single httpd process is using 6.6 MB of RSS (Resident Set Size) memory (or non-swapped physical memory) and that it is using 42 MB of VSZ (Virtual Size) memory. This depends on the number of modules you have loaded and running in Apache.</p>
<p>As shared libraries are included in this number, it’s not 100 percent accurate. We can assume that half the RSS number is “real” memory. Let’s assume that each httpd process is using (6.6/2=3.3) 4 MB of memory. So if you have 1 GB ram then divide it with 4 MB of memory, which leaves room for around 256 concurrent httpd processes.</p>
<p style="padding-left: 30px"><strong>Set MaxClients 256</strong></p>
<p>Or</p>
<p>Somebody prefers to set MaxClients using following rule<strong></strong></p>
<p style="padding-left: 30px"><strong>MaxClients = 150 x RAM (GB) </strong></p>
<p>So for example if you have 2 GB RAM (dedicated for apache) set this value to 300. In my case IT WILL BE 150</p>
<p>Or</p>
<p>Some individuals maintain that each httpd thread uses about 5 MB of “real” memory. So they determine by the following way..</p>
<p>Or</p>
<p style="padding-left: 30px"><code>MaxClients = RAM(MB)/5</code></p>
<p><code>So for example if you have 2 GB RAM (dedicated for apache) set this value to 409. In my case IT WILL BE 204(1 GB for apache)</code><em></em></p>
<p><em>Note:</em> There is no reason for you to set it any higher unless you have a specific problem with this value. A high value can lead to a complete server hang in case of a DOS attack. A value too low can create timeout problems for your clients if the limit is reached</p>
<p><strong>StartServers</strong> &#8211; Sets the number of child server processes created on startup. This setting depends greatly on the type of webserver you run. If you run low traffic websites on that server set it low to something like 5. If you have resource intensive websites on that server you should set it close to MaxClients.</p>
<p><strong>MaxRequestsPerChild</strong> &#8211; Controls the number of request the a child serves before the child is killed. This should not be set too low as it will put an unnecessary load on the apache server to recreate the child. I suggest setting it to 1000.</p>
<p>But we are going to use 2000 for handling heavy traffic load properly.</p>
<p><strong>MinSpareServers and MaxSpareServers</strong> &#8211; MaxSpareServers and MinSpareServers control how many spare (unused) child-processes Apache will keep alive while waiting for more requests to put them to use. Each child-process consumes resources, so having MaxSpareServers set too high can cause resource problems. On the other hand, if the number of unused servers drops below MinSpareServers, Apache will fork. Leave those values to: MinSpareServers 5 MaxSpareServers 10</p>
<p><strong>ServerLimit</strong>: Its better to keep Server limit same as the value of MaxClients.<strong></strong></p>
<p><strong>MaxRequestsPerChild</strong>: I’ve Kept default apache value for this one.</p>
<p>So few changes need to be made in httpd.conf file which is located in /etc/httpd/conf/ directory<strong></strong></p>
<p style="padding-left: 30px"><strong>&lt;IfModule prefork.c&gt;<br />
StartServers     140<br />
MinSpareServers    5<br />
MaxSpareServers   10<br />
ServerLimit      150<br />
MaxClients       150<br />
MaxRequestsPerChild  4000<br />
&lt;/IfModule&gt;</strong></p>
<p>[Note]: Response time depends on MaxClients. If you increase the MaxClients number, server will response more quickly for each request but  a high value can lead to a complete server hang.</p>
<p>Ab is a tool for benchmarking the performance of your Apache HyperText Transfer Protocol (HTTP) server. It does this by giving you an indication of how many requests per second your Apache installation can serve.</p>
<p>uptime command in your root login should not yield a load average above 1, and the server should respond to commands quickly<strong></strong></p>
<p style="padding-left: 30px"><strong>ab -n 10000 -c 200 -k http://your_url<br />
-c = concurrent connections<br />
-t = time limit<br />
-n = # of requests</strong></p>
<p>Keep tuning until you hit your maximum desired load average. For servers used interactively often, having a load above 3 is way too much to use the server comfortably. For servers used mostly as real servers, a maximum load average of 10 should be acceptable. More than that, and you’ll find yourself needing to reboot the server when experiencing heavy traffic conditions, because no terminal or remote console will respond quickly to commands, and managing the server will be impossible.</p>
<p><strong>How to configure few things in php.ini file for supporting huge traffic</strong></p>
<p>* Enable the compression of HTML by putting in your php.ini:<strong></strong></p>
<p style="padding-left: 30px"><strong>output_handler = ob_gzhandler</strong></p>
<p>** Switch from file based sessions to shared memory sessions. Compile PHP with the –with-mm option and<strong></strong></p>
<p style="padding-left: 30px"><strong>set session.save_handler=mm</strong></p>
<p><strong>Configure mysql. Change my.cnf file for better performance.</strong></p>
<p>The database parameters are tuned for systems with 1 GB RAM (for ISO CD images). If you have higher RAM, please change the following in the “my.cnf” MySQL configuration file under /etc/mysql or /etc directory.<strong></strong></p>
<p><strong>For a machine running with 512 MB of RAM, you can set these to:</strong></p>
<p style="padding-left: 30px"><strong>key_buffer=128M table_cache=1024 sort_buffer=64M read_buffer=2M record_buffer=4M</strong></p>
<p><strong>For a machine running with 1 GB of RAM, you can set these to:</strong></p>
<p style="padding-left: 30px"><strong>key_buffer=256M table_cache=2048 sort_buffer=128M read_buffer=2M record_buffer=8M</strong></p>
<p><strong>For a machine running with 2 GB of RAM, you can set these to:</strong></p>
<p style="padding-left: 30px"><strong>key_buffer=512M table_cache=3072 sort_buffer=256M read_buffer=2M record_buffer=8M</strong></p>
<p><strong>For a machine running with 4 GB of RAM, you can set these to:</strong></p>
<p style="padding-left: 30px"><strong>key_buffer=1G table_cache=4096 sort_buffer=512M read_buffer=2M record_buffer=8M</strong></p>
<p><strong><a title="http://blog.shabuz.com/?p=54" href="http://blog.shabuz.com/?p=54" target="_blank">Original Post</a><br />
</strong></p>
<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/07/25/how-to-tune-apache-and-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Master-Slave Replication</title>
		<link>http://blog.nataprawira.com/tech/2009/06/08/mysql-master-slave-replication/</link>
		<comments>http://blog.nataprawira.com/tech/2009/06/08/mysql-master-slave-replication/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 16:20:43 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Master-Slave]]></category>
		<category><![CDATA[Replication]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=53</guid>
		<description><![CDATA[

To setup Master-Slave Replication the first thing you need to do is create a user on the Master server that allows replication.

 # mysql -u root -p
mysql&#62; grant replication slave on *.* TO repl@&#8221;%&#8221; identified by &#8216;[repl password]&#8216;;
mysql&#62; quit

Be sure to replace [repl password] with the actual password you want to use. Also, you must [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F06%2F08%2Fmysql-master-slave-replication%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F06%2F08%2Fmysql-master-slave-replication%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p>To setup Master-Slave Replication the first thing you need to do is create a user on the Master server that allows replication.</p>
<p><span id="more-53"></span></p>
<p><strong> # mysql -u root -p<br />
mysql&gt; grant replication slave on *.* TO repl@&#8221;%&#8221; identified by &#8216;[repl password]&#8216;;<br />
mysql&gt; quit<br />
</strong><br />
Be sure to replace [repl password] with the actual password you want to use. Also, you must ensure that your firewall has port 3306:tcp open, the default port for the mysql server service.</p>
<p>Next, exit your ini file (typically /etc/my.cnf on Linux servers) to start binary logging of the Master server. You may or may not want to use the last line to ignore changes to the mysql database since that is the database used for mysql configuration and permissions.</p>
<p>Under the [mysqld] heading add the following lines:</p>
<p><strong> log-bin=mysql-bin<br />
server-id=1<br />
binlog-ignore-db=&#8221;mysql&#8221;<br />
</strong><br />
<em>Restart your mysql server service.</em></p>
<p>Before we start copying changes, we want to make sure the data on each server is the same, so dump the data from the Master server and add it to the Slave server. This can easily be performed using mysqldump as follows:</p>
<p><strong> # mysqldump -u root -p[password] [database]&gt;/home/[user]/[database].sql<br />
</strong><br />
Be sure again to replace [password] with the actual password, [database] with the actual name of each database, one at a time.</p>
<p>Now that you have a snapshot of the data, get the binary position of the log file.</p>
<p><strong> # mysql -u root -p[plain-text password]<br />
mysql&gt; SHOW MASTER STATUS;<br />
</strong><br />
The output should look something like this:</p>
<p><strong> +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| File             | Position  | Binlog_Do_DB | Binlog_Ignore_DB |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| mysql-bin.000112 |        79 |              | mysql            |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
1 row in set (0.00 sec)<br />
</strong><br />
Write down the filename and log position for use on the Slave server.</p>
<p>Next, copy the databases to your Slave server.</p>
<p><strong> # scp /home/[user]/*.sql [Slave IP]:/home/[user]/<br />
</strong><br />
At this point we are done with the Master server. Now for the Slave.</p>
<p>Edit the Slave server&#8217;s mysql configuation file (typically /etc/my.cnf on Linux servers) to identify its server number, master host and user.</p>
<p>Under the [mysqld] heading add the following lines:</p>
<p><strong> server-id=2<br />
master-host = [IP of Master Server]<br />
master-user = repl<br />
master-password = [repl password]<br />
master-port = 3306<br />
</strong><br />
Again, ensure you replace [repl password] with the actual repl user password, and [IP of Master Server] with the IP address of the Master server.</p>
<p>Insert the data from the Master server into the Slave server databases for each of the databases.</p>
<p><strong> # mysql -p[password] [database] &lt; /home/[user]/[database].sql<br />
</strong><br />
Be sure to replace [password] with the root users password, and [database] with each database&#8217;s name, one at a time.</p>
<p><em>Restart the mysql server service.<br />
</em><br />
Now log in to Mysql and configure the Slave replication.</p>
<p><strong> # mysql -u root -p<br />
mysql&gt; CHANGE MASTER TO MASTER_LOG_FILE=&#8217;[Filename written down]&#8216;,<br />
MASTER_LOG_POS=[Position written down];<br />
mysql&gt; START SLAVE;<br />
mysql&gt; SHOW SLAVE STATUS\G<br />
</strong><br />
Slave_IO_State status information should identify &#8220;Waiting for master to send event&#8221;. If it stops at &#8220;Connecting to Master&#8221; check your log file.</p>
<p>By default it is located in /var/log/mysqld.log but may be different on your system. Check your my.cnf file for the exact location of your log file.</p>
<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/06/08/mysql-master-slave-replication/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
