<?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>Think API&#187; mysql</title>
	<atom:link href="http://thinkapi.com/blog/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://thinkapi.com/blog</link>
	<description>An interface to tech thoughts</description>
	<lastBuildDate>Mon, 10 May 2010 10:32:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Codeigniter: Separating reads and writes for scaling MySQL</title>
		<link>http://thinkapi.com/blog/codeigniter-separating-reads-and-writes-for-scaling-mysql/</link>
		<comments>http://thinkapi.com/blog/codeigniter-separating-reads-and-writes-for-scaling-mysql/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 09:41:12 +0000</pubDate>
		<dc:creator>Sukumar</dc:creator>
				<category><![CDATA[Codeigniter]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[database replication]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql replication]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://thinkapi.com/blog/?p=173</guid>
		<description><![CDATA[Generally websites average a ratio of 9:1 or more for reads:writes for their applications which makes MySQL replication as one of the ways to scale you web application. The simplest configuration is to separate reads and writes with all the reads coming from the slave servers. We can implement this in codeigniter using database groups. [...]


Related posts:<ol><li><a href='http://thinkapi.com/blog/making-codeigniter-clean-urls-cleaner/' rel='bookmark' title='Permanent Link: Making Codeigniter clean URLs cleaner'>Making Codeigniter clean URLs cleaner</a> <small>Usually when working with codeigniter you come across the use...</small></li>
<li><a href='http://thinkapi.com/blog/how-to-skip-mysql-replication-counter/' rel='bookmark' title='Permanent Link: How to skip MySQL replication counter'>How to skip MySQL replication counter</a> <small>There are such times when MySQL replication stops when you...</small></li>
<li><a href='http://thinkapi.com/blog/upgrading-to-mysql-51-ga-better-wait/' rel='bookmark' title='Permanent Link: Upgrading to MySQL 5.1 GA? Better Wait'>Upgrading to MySQL 5.1 GA? Better Wait</a> <small>MySQL 5.1 General Availability has been released to the public....</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Generally websites average a ratio of 9:1 or more for reads:writes for their applications which makes MySQL replication as one of the ways to scale you web application. The simplest configuration is to separate reads and writes with all the reads coming from the slave servers.<br />
<span id="more-173"></span><br />
<div id="attachment_174" class="wp-caption aligncenter" style="width: 440px"><a href="http://www.teonator.net/2008/10/23/mysql-replication/"><img class="size-full wp-image-174" title="MySQL Database replication" src="http://thinkapi.com/blog/wp-content/uploads/2009/08/db_replication.jpg" alt="MySQL Database replication" width="430" height="450" /></a><p class="wp-caption-text">MySQL Database replication</p></div></p>
<p>We can implement this in <a href="http://codeigniter.com/" target="_blank">codeigniter</a> using database groups.<br />
Below is a sample execution.</p>
<p>Create two active groups &#8211; one for read and one for write.</p>
<p>File: system/application/config/database.php</p>
<pre class="brush: php;">
$active_group = &quot;write&quot;;
$active_record = TRUE;

$db['read']['hostname'] = &quot;localhost&quot;;
$db['read']['username'] = &quot;root&quot;;
$db['read']['password'] = &quot;&quot;;
$db['read']['database'] = &quot;read_database_name&quot;;
$db['read']['dbdriver'] = &quot;mysql&quot;;
$db['read']['dbprefix'] = &quot;&quot;;
$db['read']['pconnect'] = TRUE;
$db['read']['db_debug'] = FALSE;
$db['read']['cache_on'] = FALSE;
$db['read']['cachedir'] = &quot;&quot;;
$db['read']['char_set'] = &quot;utf8&quot;;
$db['read']['dbcollat'] = &quot;utf8_general_ci&quot;;

$db['write']['hostname'] = &quot;localhost&quot;;
$db['write']['username'] = &quot;root&quot;;
$db['write']['password'] = &quot;&quot;;
$db['write']['database'] = &quot;write_database_name&quot;;
$db['write']['dbdriver'] = &quot;mysql&quot;;
$db['write']['dbprefix'] = &quot;&quot;;
$db['write']['pconnect'] = TRUE;
$db['write']['db_debug'] = FALSE;
$db['write']['cache_on'] = FALSE;
$db['write']['cachedir'] = &quot;&quot;;
$db['write']['char_set'] = &quot;utf8&quot;;
$db['write']['dbcollat'] = &quot;utf8_general_ci&quot;;
</pre>
<p>Create separate database connections to access read and write databases separately where needed (constructor is generally a good place for this).</p>
<pre class="brush: php;">
$read_db = $this-&gt;load-&gt;database('read', TRUE);
$write_db = $this-&gt;load-&gt;database('write', TRUE);
</pre>
<p>You can now go about running queries in the usual way.</p>
<pre class="brush: php;">
/* For reads */
$query = $read_db-&gt;get('table_name');

foreach ($query-&gt;result() as $row)
{
    echo $row-&gt;title;
}

/* For writes */
$data = array(
               'title' =&gt; $title,
               'name' =&gt; $name,
               'date' =&gt; $date
            );

$write_db-&gt;insert('mytable', $data);
</pre>
<p>In case you want to try this on an application you are already running, you can leave the &#8220;default&#8221; connection group intact and create only the &#8220;read&#8221; connection group. Use it where you think you are running read heavy queries.</p>


<p>Related posts:<ol><li><a href='http://thinkapi.com/blog/making-codeigniter-clean-urls-cleaner/' rel='bookmark' title='Permanent Link: Making Codeigniter clean URLs cleaner'>Making Codeigniter clean URLs cleaner</a> <small>Usually when working with codeigniter you come across the use...</small></li>
<li><a href='http://thinkapi.com/blog/how-to-skip-mysql-replication-counter/' rel='bookmark' title='Permanent Link: How to skip MySQL replication counter'>How to skip MySQL replication counter</a> <small>There are such times when MySQL replication stops when you...</small></li>
<li><a href='http://thinkapi.com/blog/upgrading-to-mysql-51-ga-better-wait/' rel='bookmark' title='Permanent Link: Upgrading to MySQL 5.1 GA? Better Wait'>Upgrading to MySQL 5.1 GA? Better Wait</a> <small>MySQL 5.1 General Availability has been released to the public....</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://thinkapi.com/blog/codeigniter-separating-reads-and-writes-for-scaling-mysql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Upgrading to MySQL 5.1 GA? Better Wait</title>
		<link>http://thinkapi.com/blog/upgrading-to-mysql-51-ga-better-wait/</link>
		<comments>http://thinkapi.com/blog/upgrading-to-mysql-51-ga-better-wait/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 04:14:07 +0000</pubDate>
		<dc:creator>Sukumar</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Systems]]></category>
		<category><![CDATA[michael widenius]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[MySQL 5.1]]></category>
		<category><![CDATA[MySQL 5.1 GA]]></category>

		<guid isPermaLink="false">http://thinkapi.com/blog/?p=89</guid>
		<description><![CDATA[MySQL 5.1 General Availability has been released to the public. While many recommend using it and other don&#8217;t, Michael Widenius (Founder and original developer of MySQL) says it might not be worth it yet to upgrade your production databases. If WTF quotes like, We have changed the release model so that instead of focusing on [...]


Related posts:<ol><li><a href='http://thinkapi.com/blog/how-to-skip-mysql-replication-counter/' rel='bookmark' title='Permanent Link: How to skip MySQL replication counter'>How to skip MySQL replication counter</a> <small>There are such times when MySQL replication stops when you...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://dev.mysql.com/downloads/">MySQL</a> 5.1 <a href="http://en.wikipedia.org/wiki/Beta_version#GA">General Availability</a> has been released to the public. While <a href="http://www.pythian.com/blogs/1168/why-you-want-to-switch-to-mysql-51">many recommend using it</a> and <a href="http://www.mysqlperformanceblog.com/2008/06/30/mysql-51-stability/">other don&#8217;t</a>, <a href="http://monty-says.blogspot.com/2008/11/oops-we-did-it-again-mysql-51-released.html">Michael Widenius (Founder and original developer of MySQL) says</a> it might not be worth it yet to upgrade your production databases.<br />
<span id="more-89"></span><br />
If WTF quotes like,</p>
<blockquote><p>
We have changed the release model so that instead of focusing on quality and features our release is now defined by timeliness and features. Quality is not regarded to be that important.
</p></blockquote>
<p>and</p>
<blockquote><p>
Zero critical bugs is impossible: Sure, zero bugs is desirable. And at times, we internally glorify MySQL’s past, with “production level alpha releases”. Those were the days, but those days also had less complex and less interwoven features, and fewer developers to manage.
</p></blockquote>
<p>I wonder where MySQL is headed.</p>
<p>So as Monty says, you are better off not upgrading to version 5.1 if you do not plan to use its new features, atleast not without testing it for a few weeks.</p>
<p>Links:<br />
<a href="http://monty-says.blogspot.com/2008/11/oops-we-did-it-again-mysql-51-released.html">Oops, we did it again (MySQL 5.1 released as GA with crashing bugs)</a><br />
<a href="http://www.pythian.com/blogs/1168/why-you-want-to-switch-to-mysql-51">Why You Want to Switch to MySQL 5.1</a><br />
<a href="http://www.mysqlperformanceblog.com/2008/06/30/mysql-51-stability/">MySQL 5.1 Stability</a></p>


<p>Related posts:<ol><li><a href='http://thinkapi.com/blog/how-to-skip-mysql-replication-counter/' rel='bookmark' title='Permanent Link: How to skip MySQL replication counter'>How to skip MySQL replication counter</a> <small>There are such times when MySQL replication stops when you...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://thinkapi.com/blog/upgrading-to-mysql-51-ga-better-wait/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to skip MySQL replication counter</title>
		<link>http://thinkapi.com/blog/how-to-skip-mysql-replication-counter/</link>
		<comments>http://thinkapi.com/blog/how-to-skip-mysql-replication-counter/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 17:47:59 +0000</pubDate>
		<dc:creator>Sukumar</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Systems]]></category>
		<category><![CDATA[auto increment]]></category>
		<category><![CDATA[data inconsistency]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://thinkapi.com/blog/?p=9</guid>
		<description><![CDATA[There are such times when MySQL replication stops when you run certain updates on the master and the slave fails. Like for example you may have run a create table or an alter table on the master and further inserts but these DDLs get skipped and the inserts into these non-existent tables cause the slave [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>There are such times when MySQL replication stops when you run certain updates on the master and the slave fails. Like for example you may have run a create table or an alter table on the master and further inserts but these DDLs get skipped and the inserts into these non-existent tables cause the slave to error out and stop.</p>
<p>A simple way out of this is to run the missing DDLs on the slave and push the counter by a step. This is not recommended as this might cause data inconsistency.<span id="more-9"></span></p>
<p>Use the below sql to skip the counter by 1.</p>
<pre class="brush: sql;">
SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; START SLAVE;
</pre>
<p>Just remember to use the value 1 for any SQL statement that does not use AUTO_INCREMENT or LAST_INSERT_ID(), otherwise you will need to use the value 2. Statements that use AUTO_INCREMENT or LAST_INSERT_ID() take up 2 events in the binary log.</p>
<p>To skip lots of duplicate errors, you can set this in my.cnf</p>
<pre class="brush: sql;">
slave-skip-errors = 1062
</pre>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://thinkapi.com/blog/how-to-skip-mysql-replication-counter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
