<?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>Start IT up &#187; mysql</title>
	<atom:link href="http://www.techjini.com/blog/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techjini.com/blog</link>
	<description>The blog of TechJini Solutions</description>
	<lastBuildDate>Sat, 31 Jul 2010 13:31:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to set up Mysql Master-Slave Replication</title>
		<link>http://www.techjini.com/blog/2009/11/25/how-to-set-up-mysql-master-slave-replication/</link>
		<comments>http://www.techjini.com/blog/2009/11/25/how-to-set-up-mysql-master-slave-replication/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 07:35:22 +0000</pubDate>
		<dc:creator>Soumya</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.techjini.com/blog/2009/11/25/how-to-set-up-mysql-master-slave-replication/</guid>
		<description><![CDATA[Replication consists of following 3 parts&#8230;.

The master records changes to its data in its binary log (Binary Log Events).
The slave<a href="http://www.techjini.com/blog/2009/11/25/how-to-set-up-mysql-master-slave-replication/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>Replication consists of following 3 parts&#8230;.</p>
<ul>
<li>The master records changes to its data in its binary log (<em>Binary Log Events</em>).</li>
<li>The slave copies the masterâ€™s binary log events to its relay log.</li>
<li>The slave replays the events in the relay log, applying the changes to its own<br />
data using <em>Slave Thread</em>.</li>
</ul>
<p>The basic steps to set up replication are&#8230;</p>
<ul>
<li>Set up replication accounts on master server.</li>
<li>Configure the master and slave.</li>
<li>Instruct the slave to connect to and replicate from the master.</li>
</ul>
<p>Here are few assumptions&#8230;.</p>
<p><em>Master IP Address:</em> 192.168.1.<em>215<br />
Slave IP Address:</em> Â  192.168.1.<em>203<br />
Replication User:</em> replication<br />
<em>User Password:</em> slave</p>
<p>The <em>I/O Slave Thread</em> (it runs on Slave Server) makes a <em>TCP/IP</em> connection to the master. Thats why we need to create an user account on Master Server with proper privileges.</p>
<p>Now run the following query on Master to create a Slave account&#8230;.<br />
<em>mysql&gt;Â  GRANT REPLICATION SLAVE ON *.* TO &#8216;</em>replication<em>&#8216;@&#8217;192.168.1.203&#8242; IDENTIFIED BY &#8217;slave&#8217;;</em></p>
<p>Now edit <em><strong>my.cnf</strong></em> file on Master accordingly.</p>
<p><em>[mysqld]<br />
</em><em>server-idÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  = 1<br />
log-binÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  = mysql-bin<br />
log-bin-indexÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â  = mysql-log-bin.index<br />
relay-logÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  = mysql-relay-bin<br />
relay-log-indexÂ Â Â Â Â Â Â Â Â Â Â Â  = mysql-relay-bin.index<br />
expire_logs_daysÂ Â Â Â Â Â Â Â  = 10<br />
max_binlog_sizeÂ Â Â Â Â Â Â Â Â  = 100M<br />
binlog_do_dbÂ Â Â Â Â Â Â Â Â Â Â Â Â Â  = [Database Name to be Replicated]<br />
binlog_ignore_dbÂ Â Â Â Â Â Â Â  = [Database Name not to be Replicated]<br />
#binlog_ignore_dbÂ Â Â Â Â Â  = [Database Name not to be Replicated] (for more than one data base which is not supposed to be replicated)<br />
datadirÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  = /var/lib/mysql<br />
tmpdirÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  = /tmp</em></p>
<p>Now restart Master mysql server and run the following query&#8230;</p>
<p><em>mysql&gt;Â  SHOW MASTER STATUS;</em></p>
<p><a href="http://www.techjini.com/blog/wp-content/uploads/2009/11/screenshot-1.png" title="screenshot-1.png"><img src="http://www.techjini.com/blog/wp-content/uploads/2009/11/screenshot-1.png" alt="screenshot-1.png" /></a></p>
<p>Now edit <em><strong>my.cnf</strong></em> file on Slave accordingly&#8230;..</p>
<p><em>[mysqld]<br />
</em></p>
<p><em>server_idÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â  = 2<br />
master_hostÂ Â Â Â Â Â Â Â Â Â Â  = 192.168.1.215<br />
master_userÂ Â Â Â Â Â Â Â Â Â Â  = replication<br />
master_passwordÂ Â  = slave<br />
master_portÂ Â Â Â Â Â Â Â Â Â Â  = 3306<br />
relay_logÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â  = mysql-relay-bin<br />
relay-log-indexÂ Â Â Â Â Â  = mysql-relay-bin.index</em></p>
<p>We can set the value for master_host, master_user and master_password using mysql query. So it is better to avoid setting those valuesÂ  directly from configuration file.</p>
<p>If master is having data already, insert the data from master server to slave server database or each of the databases.<br />
Copy master database back up inside slave server and runÂ  the following command on slave&#8230;.</p>
<p>mysql -u[username] -p[password] [database name] &lt; directory_path/[database.sql]</p>
<p>Now Restart Mysql Slave server andÂ  run following query to synchronize master and slave&#8230;.</p>
<p><em>mysql&gt; CHANGE MASTER TO MASTER_HOST=&#8217;192.168.1.215&#8242;, MASTER_USER=&#8217;replication&#8217;, MASTER_PASSWORD=&#8217;slave&#8217;, MASTER_LOG_FILE=&#8217;mysql-bin.000004&#8242;, MASTER_LOG_POS=570;</em></p>
<p><strong>Note:</strong> <em><strong>MASTER_LOG_FILE</strong></em> and <em><strong>MASTER_LOG_POS</strong></em> values have been taken from the result of <em><strong>SHOW MASTER STATUS</strong></em></p>
<p>If a <em><strong>Slave</strong></em> is already running on your <em><strong>Slave Server</strong></em>,Â  <em><strong>Mysql Server</strong></em> will throw a error like&#8230;<br />
<em><strong>ERROR 1198 (HY000): This operation cannot be performed with a running slave; run STOP SLAVE first</strong></em></p>
<p>So run..<br />
<em>mysql&gt; STOP SLAVE;<br />
</em>AndÂ  run the query for <em><strong>CHANGING MASTER</strong></em> again.</p>
<p>If it shows an error like..<br />
<em><strong>ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log</strong></em></p>
<p>Run<em>&#8230;<br />
mysql&gt; RESET SLAVE; </em><br />
AndÂ  run the query for <em><strong>CHANGING MASTER</strong></em> again.</p>
<p>Finally start slave on slave server using..</p>
<p>mysql&gt; START SLAVE;<br />
mysql&gt; SHOW SLAVE STATUS\G</p>
<p><a href="http://www.techjini.com/blog/wp-content/uploads/2009/11/screenshot.png" title="screenshot.png"><img src="http://www.techjini.com/blog/wp-content/uploads/2009/11/screenshot.png" alt="screenshot.png" /></a></p>
<p>Congrats! Mysql Master-Slave Replication has been set up <img src='http://www.techjini.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Also we will be able to see the <em><strong>Replication Threads in </strong></em>the process list on both the <em><strong>Master</strong></em> and <em><strong>the Slave.</strong></em></p>
<p>So simply run&#8230;</p>
<p>mysql&gt; SHOW PROCESSLIST.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techjini.com/blog/2009/11/25/how-to-set-up-mysql-master-slave-replication/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySql tip #2 Taking backup ensuring multi byte characters does not become garbage</title>
		<link>http://www.techjini.com/blog/2008/12/29/mysql-tip-2-taking-backup-ensuring-multi-byte-characters-does-not-become-garbage/</link>
		<comments>http://www.techjini.com/blog/2008/12/29/mysql-tip-2-taking-backup-ensuring-multi-byte-characters-does-not-become-garbage/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 11:15:13 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.techjini.com/blog/2008/12/29/mysql-tip-2-taking-backup-ensuring-multi-byte-characters-does-not-become-garbage/</guid>
		<description><![CDATA[If you have multi byte data in your tables its important to take backup in utf8 which can be done<a href="http://www.techjini.com/blog/2008/12/29/mysql-tip-2-taking-backup-ensuring-multi-byte-characters-does-not-become-garbage/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>If you have multi byte data in your tables its important to take backup in utf8 which can be done using the command below:<br />
<code><br />
mysqldump -u root --default-character-set=utf8 DB_NAME | gzip > DB_NAME-`date +%Y%m%d%H%M`.sql.gz<br />
</code></p>
<p>The date parameter simply appends date/time to the backup.</p>
<p>In order to restore the backup taken above use following command<br />
<code><br />
gunzip < FILE_NAME.sql.gz | mysql --default-character-set=utf8 -u root DB_NAME<br />
</code></p>
<p>This will ensure that db is back up without affecting multi byte data.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techjini.com/blog/2008/12/29/mysql-tip-2-taking-backup-ensuring-multi-byte-characters-does-not-become-garbage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL tip #1 How to find size of a mysql database</title>
		<link>http://www.techjini.com/blog/2008/12/23/mysql-tip-1-how-to-find-size-of-a-mysql-database/</link>
		<comments>http://www.techjini.com/blog/2008/12/23/mysql-tip-1-how-to-find-size-of-a-mysql-database/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 05:47:28 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.techjini.com/blog/2008/12/23/mysql-tip-1-how-to-find-size-of-a-mysql-database/</guid>
		<description><![CDATA[In order to find size of your mysql databases you can run following sql querry:

SELECT table_schema &#34;Data Base Name&#34;, sum(<a href="http://www.techjini.com/blog/2008/12/23/mysql-tip-1-how-to-find-size-of-a-mysql-database/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>In order to find size of your mysql databases you can run following sql querry:</p>
<pre class="brush: sql;">
SELECT table_schema &quot;Data Base Name&quot;, sum( data_length + index_length ) / 1024 / 1024 &quot;Data Base Size in MB&quot;
FROM information_schema.TABLES GROUP BY table_schema ;
</pre>
<p>Divide it by further 1024 to get it in GB.</p>
<p>For more information read about <a href="http://dev.mysql.com/doc/refman/5.0/en/information-schema.html">INFORMATION_SCHEMA</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.techjini.com/blog/2008/12/23/mysql-tip-1-how-to-find-size-of-a-mysql-database/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
