<?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>Linux, Open Source and Web 2.0 &#187; MySQL</title>
	<atom:link href="http://www.itecsoftware.com/tag/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.itecsoftware.com</link>
	<description>Itec Software</description>
	<lastBuildDate>Wed, 16 Nov 2011 02:18:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>View Progress Of MySQL Dump Restore Or Import</title>
		<link>http://www.itecsoftware.com/view-progress-of-mysql-dump-restore-or-import?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=view-progress-of-mysql-dump-restore-or-import</link>
		<comments>http://www.itecsoftware.com/view-progress-of-mysql-dump-restore-or-import#comments</comments>
		<pubDate>Sat, 07 May 2011 19:18:50 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[bar]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[progress]]></category>
		<category><![CDATA[pv]]></category>
		<category><![CDATA[restore]]></category>

		<guid isPermaLink="false">http://www.itecsoftware.com/?p=795</guid>
		<description><![CDATA[<a href="http://www.itecsoftware.com/view-progress-of-mysql-dump-restore-or-import" title="View Progress Of MySQL Dump Restore Or Import"></a>Ever wondered why the MySQL command line tool don&#8217;t have any sort of progress information or status update? Well, you&#8217;re not alone if you do. Especially importing a GB sized dump file can take a long time, especially if the &#8230;<p class="read-more"><a href="http://www.itecsoftware.com/view-progress-of-mysql-dump-restore-or-import">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://www.itecsoftware.com/view-progress-of-mysql-dump-restore-or-import" title="View Progress Of MySQL Dump Restore Or Import"></a><!-- google_ad_section_start --><p>Ever wondered why the MySQL command line tool don&#8217;t have any sort of progress information or status update? Well, you&#8217;re not alone if you do. Especially importing a GB sized dump file can take a long time, especially if the table engine was InnoDB.</p>
<p>There are some clever utilities which can be used to accomplish just that, by giving the user simple, yet useful information about the progress of their process. Let&#8217;s look at them.</p>
<h4>Bar (Command Line Progress Bar)</h4>
<p>The Bar utility, or in full terms Command Line Progress Bar can be downloaded from <a title="Command Line Progress Bar" href="http://sourceforge.net/projects/clpbar/" target="_blank">Sourceforge</a>. If you are running Ubuntu, it&#8217;s as simple as running ‘<span style="color: #008000;">sudo apt-get install bar</span>’ to install it. You then simply pipe your MySQL import and get a nice status bar.</p>
<pre><span style="color: #008000;">shell&gt; bar -if=mysql_db_data.sql | mysql</span></pre>
<pre><span style="color: #008000;"><a href="http://www.itecsoftware.com/wp-content/uploads/2011/05/bar-1.06-screenshot1.jpg"><img class="size-full wp-image-797 alignnone" style="margin-top: 20px; margin-bottom: 20px;" title="bar-1.06-screenshot" src="http://www.itecsoftware.com/wp-content/uploads/2011/05/bar-1.06-screenshot1.jpg" alt="Bar utility screenshot" width="564" height="40" /></a>
</span></pre>
<h3></h3>
<h4><span id="more-795"></span>Piper Viewer</h4>
<p>To get a bit fancier, Piper Viewer can be inserted into any normal pipeline between two processes to give a visual indication of how quickly data is passing through, how long it has taken, how near to completion it is, and an estimate of how long it will be until completion. Observe multiple instances working in tandem,  a visual indicator of relative throughput in a complex pipeline. Download pv <a href="http://www.ivarch.com/programs/pv.shtml" target="_blank">here</a>.</p>
<pre><span style="color: #008000;">pv -cN gzip mysql_db_data.sql.gz | gzip -d | pv -cN mysql | mysql</span></pre>
<pre><span style="color: #008000;"><a href="http://www.itecsoftware.com/wp-content/uploads/2011/05/pv.png"><img class="size-full wp-image-798 alignnone" style="margin-top: 20px; margin-bottom: 20px;" title="pv Piper Viewer" src="http://www.itecsoftware.com/wp-content/uploads/2011/05/pv.png" alt="Piper Viewer" width="590" height="82" /></a></span></pre>
<pre>
</pre>
<p>Either utility will undoubtedly shed more light into your restoration processes, and let you know whether the process is still running if in doubt and wondering after an hour or more.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.itecsoftware.com/view-progress-of-mysql-dump-restore-or-import/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cross deleting records from multiple tables in mysql</title>
		<link>http://www.itecsoftware.com/cross-deleting-records-from-multiple-tables-in-mysql?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=cross-deleting-records-from-multiple-tables-in-mysql</link>
		<comments>http://www.itecsoftware.com/cross-deleting-records-from-multiple-tables-in-mysql#comments</comments>
		<pubDate>Tue, 21 Dec 2010 23:07:37 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[multiple delete]]></category>

		<guid isPermaLink="false">http://articles.itecsoftware.com/?p=621</guid>
		<description><![CDATA[<a href="http://www.itecsoftware.com/cross-deleting-records-from-multiple-tables-in-mysql" title="Cross deleting records from multiple tables in mysql"></a>I&#8217;ve been asked many times how to delete records in multiple tables in MySQL. Here are couple of methods that should get anyone started. Simple Inner Join Method The simple inner join method uses commas with an implicit inner join &#8230;<p class="read-more"><a href="http://www.itecsoftware.com/cross-deleting-records-from-multiple-tables-in-mysql">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://www.itecsoftware.com/cross-deleting-records-from-multiple-tables-in-mysql" title="Cross deleting records from multiple tables in mysql"></a><!-- google_ad_section_start --><p>I&#8217;ve been asked many times how to delete records in multiple tables in MySQL. Here are couple of methods that should get anyone started.</p>
<h4>Simple Inner Join Method</h4>
<p>The simple inner join method uses commas with an implicit inner join like in the example below. Here we&#8217;re using an items and price table, where each table has an itemId field which is what we join them on.</p>
<pre><span style="color: #008000;">DELETE i.*, p.*
FROM items i, price p
WHERE i.itemId = p.itemId
AND i.itemId = 101</span></pre>
<h4>Traditional Inner Join Method</h4>
<p>In the traditional inner join we&#8217;re keeping the join statement clear of the where clause, but it works as well. Whatever personal preference you may have. Note that you can delete individual table records from one table only, if you require to do so.</p>
<pre><span style="color: #008000;">DELETE i.*, p.*
FROM items i
INNER JOIN price p
ON i.itemId = p.itemId
WHERE i.itemId = 101</span></pre>
<h4><span id="more-621"></span>Delete records that are missing on the second table</h4>
<p>Using a left join, we can also delete records that have no corresponding record in the joined table. The following query accomplishes that. In the example below, we delete all records in the items table that have no record in the price table.</p>
<pre><span style="color: #008000;">DELETE i.*
FROM items i
LEFT JOIN price p
ON i.itemId = p.itemId
WHERE p.itemId IS NULL</span></pre>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.itecsoftware.com/cross-deleting-records-from-multiple-tables-in-mysql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WITH (NOLOCK) table hint equivalent for MySQL</title>
		<link>http://www.itecsoftware.com/with-nolock-table-hint-equivalent-for-mysql?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=with-nolock-table-hint-equivalent-for-mysql</link>
		<comments>http://www.itecsoftware.com/with-nolock-table-hint-equivalent-for-mysql#comments</comments>
		<pubDate>Mon, 06 Sep 2010 18:29:30 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[NOLOCK]]></category>
		<category><![CDATA[transaction]]></category>

		<guid isPermaLink="false">http://articles.itecsoftware.com/?p=538</guid>
		<description><![CDATA[<a href="http://www.itecsoftware.com/with-nolock-table-hint-equivalent-for-mysql" title="WITH (NOLOCK) table hint equivalent for MySQL"></a>I don&#8217;t remember how many times I was asked about an equivalent term of the infamous &#8220;NOLOCK&#8221; hint for mysql database server, hence I thought it was worth to write about it here. &#8220;WITH (NOLOCK)&#8221; is a transaction isolation levels &#8230;<p class="read-more"><a href="http://www.itecsoftware.com/with-nolock-table-hint-equivalent-for-mysql">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://www.itecsoftware.com/with-nolock-table-hint-equivalent-for-mysql" title="WITH (NOLOCK) table hint equivalent for MySQL"></a><!-- google_ad_section_start --><p>I don&#8217;t remember how many times I was asked about an equivalent term of the infamous &#8220;NOLOCK&#8221; hint for mysql database server, hence I thought it was worth to write about it here. &#8220;WITH (NOLOCK)&#8221; is a transaction isolation levels that defines how data is available during an update, or with other words it is a property that defines at what point changes made by an update operation will become available in a row, table or database to other processes.</p>
<p>The official SQL standard defines four isolation levels:</p>
<p>READ COMMITTED<br />
READ UNCOMMITTED<br />
REPEATABLE READ<br />
SERIALIZABLE</p>
<p>Oracle, SQL Server and MySQL support isolation levels. During an operation, the database engine places certain locks to maintain data integrity. Different types of locking apply to different databases (Oracle vs. MySQL), or table types (eg. MyISAM vs. InnoDB).</p>
<p>When WITH (NOLOCK) is used with SQL Server, the statement does not place a lock nor honor exclusive locks on table.  The MySQL equivalent is READ UNCOMMITTED, also known as &#8220;dirty read&#8221; because it is the lowest level of isolation. If we specify a table hint then it will override the current default isolation level. MySQL default isolation level is REPEATABLE READ which means locks will be placed for each operation, but multiple connections can read data concurrently.<span id="more-538"></span></p>
<p>SQL Server WITH (NOLOCK) looks like this:</p>
<p><span style="color: #008000;">SELECT * FROM TABLE WITH (nolock)</span></p>
<p>To achieve the same with MySQL, we change the session isolation mode using the <span style="color: #008000;">SET SESSION</span> command.</p>
<p><span style="color: #008000;">SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;<br />
SELECT * FROM TABLE_NAME ;<br />
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ ;</span></p>
<p>This statement will work similar to WITH (NOLOCK) i.e READ UNCOMMITTED data. We can also set the isolation level for all connections globally:</p>
<p><span style="color: #008000;">SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;</span></p>
<p>In addition, two system variables related to isolation also level exist in MySQL server:</p>
<p><span style="color: #008000;">SELECT @@global.tx_isolation;</span> (global isolation level)<br />
<span style="color: #008000;">SELECT @@tx_isolation;</span> (session isolation level)</p>
<p>Or set the isolation level inside a transaction:</p>
<p><span style="color: #008000;">SET TRANSACTION ISOLATION LEVEL REPEATABLE READ<br />
GO</span></p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.itecsoftware.com/with-nolock-table-hint-equivalent-for-mysql/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to find duplicate rows in a MySQL database table</title>
		<link>http://www.itecsoftware.com/how-to-find-duplicate-rows-in-a-mysql-database-table?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-find-duplicate-rows-in-a-mysql-database-table</link>
		<comments>http://www.itecsoftware.com/how-to-find-duplicate-rows-in-a-mysql-database-table#comments</comments>
		<pubDate>Thu, 22 Apr 2010 23:19:28 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[duplicate rows]]></category>
		<category><![CDATA[query]]></category>

		<guid isPermaLink="false">http://articles.itecsoftware.com/?p=364</guid>
		<description><![CDATA[<a href="http://www.itecsoftware.com/how-to-find-duplicate-rows-in-a-mysql-database-table" title="How to find duplicate rows in a MySQL database table"></a>I&#8217;ve been asked the question &#8220;How can I return duplicate rows only from a MySQL db table&#8221; so many times already, that I&#8217;ve decided to post it here in a short article. It is not something intuitive or readily available &#8230;<p class="read-more"><a href="http://www.itecsoftware.com/how-to-find-duplicate-rows-in-a-mysql-database-table">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://www.itecsoftware.com/how-to-find-duplicate-rows-in-a-mysql-database-table" title="How to find duplicate rows in a MySQL database table"></a><!-- google_ad_section_start --><p>I&#8217;ve been asked the question &#8220;How can I return duplicate rows only from a MySQL db table&#8221; so many times already, that I&#8217;ve decided to post it here in a short article.</p>
<p>It is not something intuitive or readily available (at least it seems), but the solution is short and very simple.</p>
<p>While this query:</p>
<pre><span style="color: #008000;">SELECT DISTINCT column1
FROM table1</span></pre>
<p>gives us all records without the duplicates, this one returns only the duplicate ones:</p>
<pre>
<pre><span style="color: #008000;">SELECT DISTINCT column1
FROM table1
GROUP BY column1
HAVING COUNT(column1) &gt; 1</span></pre>
</pre>
<p>And by increasing the having count, you can retrieve records with multiple occurrences.</p>
<pre></pre>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.itecsoftware.com/how-to-find-duplicate-rows-in-a-mysql-database-table/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; How To Analyze, Repair and Optimize all Tables</title>
		<link>http://www.itecsoftware.com/mysql-how-to-analyze-repair-and-optimize-all-tables?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-how-to-analyze-repair-and-optimize-all-tables</link>
		<comments>http://www.itecsoftware.com/mysql-how-to-analyze-repair-and-optimize-all-tables#comments</comments>
		<pubDate>Mon, 02 Nov 2009 18:14:10 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Useful Stuff]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[analyze table]]></category>
		<category><![CDATA[mysqlcheck]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[repair table]]></category>

		<guid isPermaLink="false">http://articles.itecsoftware.com/?p=319</guid>
		<description><![CDATA[<a href="http://www.itecsoftware.com/mysql-how-to-analyze-repair-and-optimize-all-tables" title="MySQL - How To Analyze, Repair and Optimize all Tables"></a>Ever come across a situation, where you&#8217;d like to check all tables in a database and have them all repaired and optimized? My guess is yes. In case you didn&#8217;t know, there is a helpful MySQL utility called mysqlcheck, available &#8230;<p class="read-more"><a href="http://www.itecsoftware.com/mysql-how-to-analyze-repair-and-optimize-all-tables">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://www.itecsoftware.com/mysql-how-to-analyze-repair-and-optimize-all-tables" title="MySQL - How To Analyze, Repair and Optimize all Tables"></a><!-- google_ad_section_start --><p>Ever come across a situation, where you&#8217;d like to check all tables in a database and have them all repaired and optimized? My guess is yes.</p>
<p>In case you didn&#8217;t know, there is a helpful MySQL utility called mysqlcheck, available as of version 3.23.38. It does exactly what we need.</p>
<p>To check all tables in all databases for corruption and errors and also fix them in one go, this is your command:</p>
<p><span style="color: #003300;"><em><span style="color: #008000;">mysqlcheck -u username -p password  &#8211;check &#8211;optimize &#8211;auto-repair &#8211;all-databases</span></em></span></p>
<p>mysqlcheck executes statements like CHECK TABLE, REPAIR TABLE, ANALYZE TABLE, and OPTIMIZE TABLE and chooses the best statements for any given operation and storage engine.</p>
<p>Note that the operations complete a lot faster if you can afford to to disable any external services, especially if your database is large.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.itecsoftware.com/mysql-how-to-analyze-repair-and-optimize-all-tables/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to install MySQL Server, PHP and Apache on a Mac</title>
		<link>http://www.itecsoftware.com/how-to-install-mysql-server-php-and-apache-on-a-mac?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-install-mysql-server-php-and-apache-on-a-mac</link>
		<comments>http://www.itecsoftware.com/how-to-install-mysql-server-php-and-apache-on-a-mac#comments</comments>
		<pubDate>Sat, 24 Oct 2009 19:39:50 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Snow Leopard]]></category>

		<guid isPermaLink="false">http://articles.itecsoftware.com/?p=301</guid>
		<description><![CDATA[<a href="http://www.itecsoftware.com/how-to-install-mysql-server-php-and-apache-on-a-mac" title="How to install MySQL Server, PHP and Apache on a Mac"></a>These instructions lead you thru the installation of the latest LAMP Stack on MacOS X Snow Leopard. 1 &#8211; Download the installation image from MySQL website here. Then double-click to mount and open the disk image. 2 &#8211; Install MySQL &#8230;<p class="read-more"><a href="http://www.itecsoftware.com/how-to-install-mysql-server-php-and-apache-on-a-mac">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://www.itecsoftware.com/how-to-install-mysql-server-php-and-apache-on-a-mac" title="How to install MySQL Server, PHP and Apache on a Mac"></a><!-- google_ad_section_start --><p>These instructions lead you thru the installation of the latest LAMP Stack on MacOS X Snow Leopard.</p>
<p>1 &#8211; Download the installation image from MySQL website <a href="http://dev.mysql.com/downloads/mysql/5.1.html#macosx-dmg" target="_blank">here</a>. Then double-click to mount and open the disk image.</p>
<p>2 &#8211; Install MySQL Server by double clicking the package &#8220;mysql-5.1.*****.pkg&#8221; and follow the menu, accepting the default values, unless you want to change something and know exactly what you&#8217;re doing.</p>
<p>3 &#8211; Install MySQL Startup Item by double-clicking the package &#8220;MySQLStartupitem.pkg&#8221; and follow the menu.</p>
<p>4 &#8211; Install MySQL Preference Pane by double-clicking the file &#8220;MySQL.prefPane&#8221; and follow the menu. This item will simplify the management of your SQL Server. You can now use the &#8220;System Preferences&#8221; panel to start and stop the database server.</p>
<p>5 &#8211; Enable the php module in your apache config file. You might know that Snow Leopard already ships with Apache 2.2 and PHP 5.3, but it needs a couple of tweaks to make it work smoothly. So, open /etc/apache2/httpd.conf and search for &#8220;php5_module&#8221;. Remove the comment (#) in front of the line, save and close the file, then restart apache (sudo apachectl restart)</p>
<p><span id="more-301"></span></p>
<p>6 &#8211; Testing Apache/PHP. Let&#8217;s create an info file so we know what we got. Navigate to /Library/WebServer/Documents and create a file called phpinfo.php. Put the following line into the file, save and close. &#8220;&lt;?php phpinfo(); ?&gt;&#8221;. Now open your favorite browser and hit it (http://localhost/phpinfo.php). You should see a page like the one below, which shows you configuration details, modules enabled and other useful information.</p>
<p><img class="size-medium wp-image-307  alignleft" style="margin: 10px;" title="php-info-page" src="http://www.itecsoftware.com/wp-content/uploads/2009/10/php-info-page-300x195.png" alt="PHP Info Page" width="300" height="195" /></p>
<p>7 &#8211; There is no php.ini out of the box (as you may have discovered by looking at the phpinfo page), but there is a sample file called &#8220;php.ini.default&#8221; which we&#8217;re going to use. Copy this file and save it as php.ini.</p>
<p>8 &#8211; Set the default time zone. As PHP 5.3 requires the timezone to be set, let&#8217;s do this inside php.ini, so we don&#8217;t have to worry about it anymore. You can always override it in your application&#8217;s bootstrap, if needed. Open /etc/php.ini and search for &#8220;[Date]&#8220;. Uncomment the line &#8220;date.timezone = &#8221; and add your timezone. Check the <a href="http://www.php.net/manual/en/timezones.php" target="_blank">php manual</a> for acceptable values. (example: date.timezone = &#8216;America/Los Angeles&#8217;)</p>
<p>And that&#8217;s it. You should now have a fully functional LAMP stack with Apache, PHP and MySQL server.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.itecsoftware.com/how-to-install-mysql-server-php-and-apache-on-a-mac/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setup MySQL Replication the easy way</title>
		<link>http://www.itecsoftware.com/setup-mysql-replication-the-easy-way?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=setup-mysql-replication-the-easy-way</link>
		<comments>http://www.itecsoftware.com/setup-mysql-replication-the-easy-way#comments</comments>
		<pubDate>Fri, 14 Aug 2009 18:53:53 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[master]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[slave]]></category>

		<guid isPermaLink="false">http://articles.itecsoftware.com/?p=216</guid>
		<description><![CDATA[<a href="http://www.itecsoftware.com/setup-mysql-replication-the-easy-way" title="Setup MySQL Replication the easy way"></a>1. Configure the Master We will need to modify a file called my.cnf, which is the main configuration file for mysql. On most systems it&#8217;s located in /etc/ or /etc/mysql/ and it contains all important configuration data. First, let&#8217;s ensure &#8230;<p class="read-more"><a href="http://www.itecsoftware.com/setup-mysql-replication-the-easy-way">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://www.itecsoftware.com/setup-mysql-replication-the-easy-way" title="Setup MySQL Replication the easy way"></a><!-- google_ad_section_start --><p><span style="text-decoration: underline;"><strong>1. Configure the Master</strong></span></p>
<p>We will need to modify a file called <em>my.cnf</em>, which is the main configuration file for mysql. On most systems it&#8217;s located in /etc/ or /etc/mysql/ and it contains all important configuration data.</p>
<p>First, let&#8217;s ensure that networking is enabled and mysql listens on all, or at least the client&#8217;s IP addresses. We also have to tell mysql what file to write the logs to and from which databases to keep logging, so that the Slave can pick up the changes. And finally we need to assign a unique ID to the Master.</p>
<p>All this info is contained within the following lines in your my.cnf file. Please note that the position of these entries can be spread throughout the file, so you might have to search for each of them.</p>
<address><span style="color: #008000;">#skip-networking</span></address>
<address><span style="color: #008000;"># bind-address = xxx.xxx.xxx.xxx (this can be the Slave&#8217;s IP address. if you&#8217;re not sure, leave it commented out)</span></address>
<address><span style="color: #008000;">log-bin = /var/log/mysql/mydatabase-bin.log</span></address>
<address><span style="color: #008000;">server-id = 1</span></address>
<address> </address>
<p><span style="color: #000000;">Restart the server. Then log into mysql and create a user with replication privileges:</span></p>
<address><span style="color: #008000;">GRANT REPLICATION SLAVE ON *.* TO &#8216;slave_user&#8217;@'%&#8217; IDENTIFIED BY &#8216;&lt;password&gt;&#8217;;<br />
FLUSH PRIVILEGES; </span></address>
<address><span style="color: #008000;">USE mydatabase;</span></address>
<p>The next 3 steps is to lock all tables on the database, take a backup and get the replication sequence ID. We&#8217;ll use the backup later on the Slave to establish the baseline, and tell it to start replication starting from the sequence ID.</p>
<p><span id="more-216"></span></p>
<p>If you&#8217;re performing this action on a high volume production system, I&#8217;d recommend to plan these next steps carefully, as the db will be locked for writing during the backup process.</p>
<address><span style="color: #003300;"> <span style="color: #008000;">FLUSH TABLES WITH READ LOCK;<br />
SHOW MASTER STATUS; </span></span></address>
<p><span style="color: #003300;"><span style="color: #000000;">Write down the &#8220;Position&#8221; number, it&#8217;s the sequence ID and the bin log file. Since the tables are locked, you&#8217;ll need to open a second terminal and log into mysql and perform the backup:</span></span></p>
<address><span style="color: #008000;">mysqldump -u root -p&lt;password&gt; &#8211;opt mydatabase | gzip &gt; mydatabasedump.sql.gz</span></address>
<p>Once the backup is finished, unlock the tables in the first terminal.</p>
<address><span style="color: #008000;">UNLOCK TABLES;</span></address>
<address></address>
<p>Whew, we&#8217;re done with the Master. Wasn&#8217;t that hard, was it? Now on to the Slave.</p>
<div style="float: left; width: 250px; margin-right: 20px;"><script type="text/javascript">// <![CDATA[
    google_ad_client = "pub-5075229468189091"; /* 250x250, created 8/18/09 */ google_ad_slot = "1952402743"; google_ad_width = 250; google_ad_height = 250;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></div>
<p><strong><span style="text-decoration: underline;">2. Configure the Slave</span></strong></p>
<p>You&#8217;ll have to copy the backup file to the Slave server and extract it (gzip -d). On the Slave, let&#8217;s first create the database and restore the dump we took from the Master.</p>
<p>After loging into mysql from the terminal:</p>
<address><span style="color: #008000;">CREATE DATABASE mydatabase;</span></address>
<address><span style="color: #008000;">exit;</span></address>
<address><span style="color: #008000;">mysql -u&lt;user&gt; -p&lt;password&gt; mydatabase &lt; mydatabasedump.sql;</span></address>
<p>Then we&#8217;ll go on to configure my.cnf on the Slave. As I stated earlier, the position of these entries can be spread throughout the file, so you might have to search for each of them or they might not even be present, so you have to add them.</p>
<address><span style="color: #008000;">server-id=2<br />
replicate-do-db=mydatabase</span></address>
<p><span style="text-decoration: underline;"><span style="color: #000000;"><strong>3. setup parameters and start replication</strong></span></span></p>
<p>Restart MySQL, login to mysql and stop the Slave. You now will need the info you wrote down during the &#8220;SHOW MASTER STATUS&#8221; command.</p>
<address> <span style="color: #008000;">SLAVE STOP;</span></address>
<address><span style="color: #008000;">CHANGE MASTER TO MASTER_HOST=&#8217;IP address of Master&#8217;, MASTER_USER=&#8217;&lt;user&gt;&#8217;, MASTER_PASSWORD=&#8217;&lt;password&gt;&#8217;, MASTER_LOG_FILE=&#8217;&lt;the log bin file&gt;&#8217;, MASTER_LOG_POS=&lt;the sequence ID&gt;; </span></address>
<p>Example: CHANGE MASTER TO MASTER_HOST=&#8217;192.168.1.1&#8242;, MASTER_USER=&#8217;slave_user&#8217;, MASTER_PASSWORD=&#8217;1234&#8242;, MASTER_LOG_FILE=&#8217;mysql-bin.001&#8242;, MASTER_LOG_POS=256;</p>
<p>Finally, we start the Slave with the new settings and get replication started. Still from the terminal, logged in to mysql:</p>
<address><span style="color: #008000;">START SLAVE;</span></address>
<p>That&#8217;s all there is to it. There are commands like &#8220;SHOW SLAVE STATUS&#8221; that let&#8217;s you check if replication is working.</p>
<p>Update:</p>
<p>If you have problems getting &#8220;Slave_IO_Running&#8221; to &#8220;Yes&#8221; state, you might have to flush the tables on the slave, like this:</p>
<p><span style="color: #003300;"><em>STOP SLAVE;</em></span></p>
<p><span style="color: #003300;"><em>FLUSH TABLES WITH READ LOCK;</em></span></p>
<p><span style="color: #003300;"><em>UNLOCK TABLES;</em></span></p>
<p><span style="color: #003300;"><em>START SLAVE;</em></span></p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.itecsoftware.com/setup-mysql-replication-the-easy-way/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>INSERT IF NOT EXISTS in MySql</title>
		<link>http://www.itecsoftware.com/insert-if-not-exists-in-mysql?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=insert-if-not-exists-in-mysql</link>
		<comments>http://www.itecsoftware.com/insert-if-not-exists-in-mysql#comments</comments>
		<pubDate>Wed, 03 Jun 2009 20:10:34 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[insert if not exists]]></category>
		<category><![CDATA[lamp]]></category>
		<category><![CDATA[replace into]]></category>

		<guid isPermaLink="false">http://articles.itecsoftware.com/?p=156</guid>
		<description><![CDATA[ <p class="read-more"><a href="http://www.itecsoftware.com/insert-if-not-exists-in-mysql">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://www.itecsoftware.com/insert-if-not-exists-in-mysql" title="INSERT IF NOT EXISTS in MySql"></a><!-- google_ad_section_start --><p>INSERT IGNORE is the syntax that does mimic INSERT IF NOT EXISTS, as there is no direct command as stated in the title, at least not in the current release of MySql.<br />
The statement INSERT IGNORE (and to some extent REPLACE INTO) does essentially the same thing, inserting a record if that given record does not exists.<br />See the following samples:</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-5075229468189091";
google_ad_slot = "2446713154";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script><br />
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></p>
<p><span id="more-156"></span></p>
<p>Sample:</p>
<p>INSERT IGNORE INTO `table`<br />
SET &#8216;column_1` = `value_1`,<br />
`column_2` = `value_2&#8242;;</p>
<p>If you&#8217;re concerned with existing data that might result in duplicate records, or error out due to duplicate id&#8217;s, use REPLACE. MySql will check if the record exists, replace the values given and insert it if the record does not exist.</p>
<p>Sample:</p>
<p>REPLACE INTO `table`<br />
SET &#8216;column_1` = `value_1`,<br />
`column_2` = `value_2&#8242;;</p>
<p>References: <a href="http://dev.mysql.com/doc/refman/5.1/en/insert.html" target="_blank">INSERT IGNORE</a> and <a href="http://dev.mysql.com/doc/refman/5.0/en/replace.html" target="_blank">REPLACE INTO</a></p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.itecsoftware.com/insert-if-not-exists-in-mysql/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 16/52 queries in 0.029 seconds using memcached
Object Caching 998/1100 objects using memcached

Served from: www.itecsoftware.com @ 2012-02-08 18:24:49 -->
