<?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>MySQL Fanboy</title>
	<atom:link href="/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlfanboy.com</link>
	<description>Almost crazy about Opensource / Free  information.</description>
	<lastBuildDate>Fri, 30 Sep 2011 17:36:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>What can I DROP?</title>
		<link>http://www.mysqlfanboy.com/?p=675</link>
		<comments>http://www.mysqlfanboy.com/?p=675#comments</comments>
		<pubDate>Fri, 30 Sep 2011 17:35:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HOW TO]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=675</guid>
		<description><![CDATA[So you have inherited a MySQL server and no one know what applications are use what databases.   Space is every tight and every night transactions logs almost fill your hard disk.  The server was once used as a replication server and it seems every database the company uses is duplicated here. You could do [...]]]></description>
			<content:encoded><![CDATA[<p>So you have inherited a MySQL server and no one know what applications are use what databases.   Space is every tight and every night transactions logs almost fill your hard disk.  The server was once used as a replication server and it seems every database the company uses is duplicated here.</p>
<p>You could do a full dump, drop everything and wait for the requests to restore. (This might be OK on a test database.)</p>
<p>We could ask MySQL for all the databases that have tables that have been updated in the last 30 days.</p>
<pre>$ mysql information_schema -e  \
"select DISTINCT TABLE_SCHEMA as NAME from TABLES
  WHERE UPDATE_TIME IS NOT NULL and UPDATE_TIME &gt; NOW() - INTERVAL 30 DAY"  \
&gt; Databases</pre>
<p>But this only gives a list of databases that have changed.  What about tables that are only read from?</p>
<p>Bin-Logs don&#8217;t help because they too only have updates.  What we really need is a long snapshot of the general log. But, starting the general log will just fill your disk space even more.</p>
<p>As long as all queries are remote we can use tcpdump.</p>
<p>Filter all the MySQL connections for  &#8216;FROM tablenames&#8217;.</p>
<pre>$ tcpdump -i eth1 -s 0 -l -w - dst port 3306 | strings | \
 sed -n 's/\(.*\)\(from.*\)/\2/p' | awk '{print $2}' &gt; TableList
 $ cat TableList | sort | uniq &gt; ShortList</pre>
<p>Some of the queries may reference databases.tablename so we can filter out the database names and add them to your Database list.</p>
<pre>$ cat TableList | sed -n 's/\./ /p' | awk '{print $1}' | sort | uniq &gt;&gt; Databases</pre>
<p>Now for the queries that only use table names. We need to find the database each belongs to.  This isn&#8217;t completely accurate because the table name may be in more then one databases.</p>
<pre>$  for x in `cat TableList | sort | uniq` ;
 do
 mysql information_schema -e "select TABLE_SCHEMA from TABLES where TABLE_NAME='$x'\G"  \
 | grep TABLE | awk '{print $2}' ;
 done | sort | uniq &gt;&gt; Databases</pre>
<p>To create the final list of database that should not be dropped.</p>
<pre>$ sort Databases | uniq &gt; KEEPTHESE ; cat KEEPTHESE</pre>
<p>Now you can do the deed with some confidence your not removing anything being used.</p>
<p>&nbsp;</p>
<p><img class="alignleft" src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>P.S.  Did I tell you, Never do anything you can&#8217;t reverse.   Make a BACKUP FIRST!</p>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F%3Fp%3D675&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=What can I DROP? - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/?feed=rss2&#038;p=675</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Full Monty- Part 2</title>
		<link>http://www.mysqlfanboy.com/?p=651</link>
		<comments>http://www.mysqlfanboy.com/?p=651#comments</comments>
		<pubDate>Mon, 15 Aug 2011 19:39:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Commentary]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=651</guid>
		<description><![CDATA[Installing DRDB in CentOS 5.6. In Part 1 I when through the process of preparing a number of CentOS 5.6 servers. Now make the services they’ll preform more stable. High Availability (HA) I’ll be presenting two ways to provide redundant data and high available services. First, Pacemaker &#8211; with DRDB will duplicate your data at [...]]]></description>
			<content:encoded><![CDATA[<p>Installing DRDB in CentOS 5.6.
</p>
<p>In <a href="/2011/08/the-full-monty-centos-5-5-drbd-pacemaker-mysql-tunsten-replication-and-more/">Part 1</a> I when through the process of preparing a number of <a href="https://www.centos.org/">CentOS </a>5.6 servers. Now make the services they’ll preform more stable.</p>
<h3>High Availability (HA)</h3>
<p>I’ll be presenting two ways to provide redundant data and high available services. First, Pacemaker &#8211; with <a href="www.drbd.org">DRDB </a>will duplicate your data at the disk partition level and watch for failures. Should the hardware failure, Pacemaker will take all the needed steps to start MySQL on the Hot Stand By (HSB). This is not perfect. Should someone run ‘rm *’ or drop a database DRDB will duplicate the loss on the HSB.</p>
<p>In another part, I’ll use <a href="http://code.google.com/p/tungsten-replicator/">Tungsten replicator</a>. It offers a set of features that surpass the built-in MySQL replicator. The community version of Tungsten has global transaction IDs so even with many slaves, global transactions IDs make turning a slave into the master easy. Tungsten replicator is not a HA service. You have to manually fail to a new master. Tungsten Enterprise (if you have money) solves all the issues. With the tools the enterprise version supplies you can easily migrate the “master” server to any slave.</p>
<h3>HA with Pacemaker:</h3>
<p>Neither RedHat or CentOS supply PaceMaker packages. Redhat support their own propitiatory clustering suite. CentOS is suck trying to maintain compatibility with Redhat while still giving you a high availability system. CentOS does supply heartbeat and openais but not pacemaker. Thankful Redhat helps out by supporting the <a href="http://fedoraproject.org/">Fedora project</a> and in turn Fedora provide an <a href="http://www.google.com/url?q=http%3A%2F%2Fwww.clusterlabs.org%2Frpm%2F&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNF0XcJrX5pKiMfKi3GCKycEfrMosA">EPEL repository for Redhat 5</a>.</p>
<p>The Pacemaker packages in Fedora&#8217;s EPEL directories are built against some additional packages that don&#8217;t exist on vanilla RHEL/CentOS installs. For more information on EPEL, see <a href="http://fedoraproject.org/wiki/EPEL/FAQ">http://fedoraproject.org/wiki/EPEL/FAQ</a> So before installing Pacemaker, you will first need to tell the machine how to find the EPEL packages Pacemaker depends on. To do this, download and install the EPEL package that matches your RHEL/CentOS version.</p>
<p>LINBIT is the primary maintainer of DRBD and offers a product and service portfolio for exactly what we are building here. They have produced a <a href="http://www.google.com/url?q=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dd0jXgrtkVJ4">video </a>that takes you through this same process using the the DRDB Console Manager. I&#8217;m going to take you through the same process by hand. I hope this way you will better understand the management touch points.</p>
<h3>DRBD Installation:</h3>
<p>I build two computer alike in every way (clones) and use DRBD to sync the data partitions on each. CentOS provides the packages needed.</p>
<pre><strong> # <span style="color: #008000;">wget http://www.clusterlabs.org/rpm/epel-5/clusterlabs.repo</span>  
 # <span style="color: #008000;">mv clusterlabs.repo /etc/yum.repos.d</span>  
 # <span style="color: #008000;">rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm</span>  
 # <span style="color: #008000;">yum -y install pacemaker.x86_64 heartbeat.x86_64 drbd83.x86_64 kmod-drbd83.x86_64</span></strong>
<strong> # <span style="color: #008000;">/sbin/chkconfig --add heartbeat</span>  
 # <span style="color: #008000;">depmod</span>  
 # <span style="color: #008000;">modprobe drbd</span></strong></pre>
<h3>DRBD Configuration:</h3>
<p>On both machines (db1 and db2), edit the DRBD configuration file. The host names must be the save as returned by &#8216;hostname&#8217; command. You may also need to edit the host name in <strong>/etc/sysconfig/network</strong>. I have highlighted parts you will need to edit in red.</p>
<p>To replace the shared-secret, select at least half of the characters from the &#8220;63 random alpha-numeric characters&#8221; from Gibson Research <a href="http://www.grc.com/passwords.htm">Ultra High Security Passwords</a>.</p>
<pre><strong> # <span style="color: #008000;">vi /etc/drbd.conf</span></strong></pre>
<pre> include "drbd.d/global.conf";
 include "drbd.d/*.res";</pre>
<pre><strong># <span style="color: #008000;">vi /etc/drbd.d/global.conf</span></strong></pre>
<pre><span style="color: #0000ff;">global { usage-count yes; }
common { startup { degr-wfc-timeout 0; }
net { cram-hmac-alg sha1; shared-secret <span style="color: #ff0000;">R4x2alEkxtIg2kzbXqUL6l4uoTI7Ab7Qt</span>; }
disk { on-io-error detach; } }</span></pre>
<pre># <strong><span style="color: #008000;">hostname</span></strong>
 db1.grennan.com</pre>
<pre><strong># <span style="color: #008000;">vi /etc/drbd.d/db.res</span></strong></pre>
<pre><span style="color: #0000ff;">resource db { protocol C; syncer { rate 10M; }
on <span style="color: #ff0000;">db1.grennan.com</span> { device /dev/<span style="color: #ff0000;">drbd0</span>; disk /dev/<span style="color: #ff0000;">md3</span>; address <span style="color: #ff0000;">192.168.4.1</span>:7788; flexible-meta-disk internal; }
on <span style="color: #ff0000;">db2.grennan.com</span> { device /dev/<span style="color: #ff0000;">drbd0</span>; disk /dev/<span style="color: #ff0000;">md3</span>; address <span style="color: #ff0000;">192.168.4.2</span>:7788; flexible-meta-disk internal; } }</span></pre>
<pre><strong> # <span style="color: #008000;">scp -r /etc/drbd.d db2:/etc</span>  # <span style="color: #008000;">scp -r /etc/drbd.conf db2:/etc</span></strong></pre>
<h3>Manage DRDB processes:</h3>
<p>If the disk was formatted during the OS install you may need to erase the ext3 file system info on both DB1 and DB2.</p>
<pre><strong> # <span style="color: #008000;">umount /data</span>  # <span style="color: #008000;">dd if=/dev/zero of=/dev/<span style="color: #ff0000;">md3</span> count=2048</span></strong></pre>
<p>Write the DRBD meta data on both DB1 and DB2.</p>
<p># <span style="color: #008000;">drbdadm create-md db</span></p>
<p>On &gt;&gt;&gt; DB1 only &lt;&lt;&lt;</p>
<pre><strong>  # <span style="color: #008000;">drbdadm adjust db</span> </strong>
<strong>  # <span style="color: #008000;">drbdsetup /dev/<span style="color: #ff0000;">drbd0</span> primary -o</span></strong>
<strong>  # <span style="color: #008000;">service drbd start</span></strong></pre>
<p>On DB2</p>
<p><strong>  #<span style="color: #008000;"> service drbd start</span></strong></p>
<p>Did you miss the &gt;&gt;&gt; DB1 only &lt;&lt;&lt; above?   If you did you&#8217;ll need to re-run &#8216;drbdsetup /dev/drbd0 primary -o&#8217; on DB1.</p>
<p><strong><span style="color: #ff0000;">WAIT until the sync process completes.</span></strong></p>
<p>Back on DB1 create the file system and mount it.</p>
<pre><strong>  # <span style="color: #008000;">mkdir /data</span> </strong>
<strong>  # <span style="color: #008000;">mkfs -j /dev/<span style="color: #ff0000;">drbd0</span></span></strong>
<strong>  # <span style="color: #008000;">tune2fs -c -1 -i 0 /dev/<span style="color: #ff0000;">drbd0</span></span></strong>
<strong>  # <span style="color: #008000;">mkdir /data</span></strong>
<strong>  # <span style="color: #008000;">mount -o rw /dev/<span style="color: #ff0000;">drbd0</span> /data</span></strong></pre>
<p>Don&#8217;t forget to make the /data directory on DB2.</p>
<pre><strong>  # <span style="color: #008000;">mkdir /data/mysql</span></strong>
<strong>  # <span style="color: #008000;">cat /proc/drbd</span></strong></pre>
<pre>version: 8.3.8 (api:88/proto:86-94)
 GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:09</pre>
<pre>1: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r----
 ns:2433920 nr:0 dw:0 dr:2433920 al:0 bm:148 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:28530088
 [==&gt;.................] sync'ed: 21.9% (27860/30236)M delay_probe: 757
 finish: 4:57:11 speed: 1,248 (6,404) K/sec</pre>
<p>In the next post I’ll go through installing MySQL in preparation for configuring Pacemaker. Then I’ll show you how to test fail over.</p>
<p>In the next part I will go over setting up MySQL.</p>
<p><img class="alignleft" src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F%3Fp%3D651&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=The Full Monty- Part 2 - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/?feed=rss2&#038;p=651</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Full Monty &#8211; CentOS 5.5, drbd, PaceMaker, MySQL, Tunsten Replication and more</title>
		<link>http://www.mysqlfanboy.com/?p=556</link>
		<comments>http://www.mysqlfanboy.com/?p=556#comments</comments>
		<pubDate>Mon, 01 Aug 2011 05:00:36 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[DRDB]]></category>
		<category><![CDATA[HA]]></category>
		<category><![CDATA[Heartbeat]]></category>
		<category><![CDATA[HOW TO]]></category>
		<category><![CDATA[Tips & Tricks]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=556</guid>
		<description><![CDATA[PART 1 – This will be a multi part post. After years of supporting MySQL, for many different companies, I&#8217;ve seen this story played out again and again. The company: chooses a Database Management System (MySQL) installs the DBMS on a computer with other processes writes many programs to access the data (Without concern on [...]]]></description>
			<content:encoded><![CDATA[<h3>PART 1 – This will be a multi part post.</h3>
<p>After years of supporting MySQL, for many different companies, I&#8217;ve seen this story played out again and again.<br />
The company:</p>
<ul>
<li>chooses a Database Management System (MySQL)</li>
<li>installs the DBMS on a computer with other processes</li>
<li>writes many programs to access the data (Without concern on how the queries are written.)</li>
<li>moves DBMS to a computer of its own and writes more programs</li>
<li>buy bigger computer to run the DBMS and writes more programs</li>
<li>tires of DBMS response times and outages caused by developers working on production systems and hires a Database Administrator to fix the mess</li>
</ul>
<p>This is a step by step description of  how I build a highly available, production MySQL servers. Like most things it life, these problems can be avoided with a little extra work at the start.</p>
<p>My first goal is to create a MySQL DBMS that with 99.999% up time. MySQL can distribute read requests but not writes. This make write service a single point of failure. To fix this you can either turn a slave server into the master or provide a hot standby to become the master.</p>
<p>My second goal is scalability. This is done by creating more read only slave servers. More slaves complicate turning one of them into the master should the master fail. The enterprise version Continuent’s Tungsten replicator fixes this. But, my goal is to do this on the cheep for start-ups while providing flexibility for the future. With DRBD and Pacemaker I can create a hot standby for the master server.</p>
<p>I have chosen these programs and utilities because they are free. Enterprise support is available for each.</p>
<p>Here is what I’m using:</p>
<ul>
<li><a href="http://centos.org/">CentOS </a>(Redhat) 5.6</li>
<li><a href="http://www.drbd.org/">DRBD </a>disk replication for a hot standby</li>
<li>MySQL 5.1.xx (<a href="http://www.percona.com/">Percona</a>) or <a href="http://askmonty.org/">MeriaDB</a></li>
<li><a href="http://www.linux-ha.org/wiki/Heartbeat">Heartbeat</a></li>
<li><a href="http://www.clusterlabs.org/">Pacemaker </a>for failure recover to the hot standby</li>
<li><a href="https://code.google.com/p/tungsten-replicator/">Tunsten </a>data replication</li>
<li><a href="http://www.maatkit.org/">MaaKit </a>a toolkit for users, developers, and administrators of open-source databases</li>
<li><a href="http://code.openark.org/forge/openark-kit">OpenArk Kit</a> &#8211; a set of utilities for MySQL</li>
<li><a href="http://www.percona.com/docs/wiki/percona-xtrabackup:start">xtrabackup </a>for database backups</li>
<li><a href="https://launchpad.net/mydumper">mydumper</a> for quick dumps
</li>
<li><a href="http://mysqlsandbox.net/">MySQL Sandbox</a> for testing</li>
<li><a href="/mytop/">mytop</a> and <a href="http://www.xaprb.com/blog/2006/07/02/innotop-mysql-innodb-monitor/">innotop</a></li>
<li><a href="http://hackmysql.com/mysqlsniffer">mysqlsniffer </a></li>
</ul>
<p>I&#8217;ve worked hard to make this just cut and past. I enjoyed the work. I hope you do to.</p>
<p><span id="more-556"></span></p>
<p><strong>NOTE: </strong> Type the <strong><span style="color: #339966;">GREEN</span></strong> stuff, cut and past the <strong><span style="color: #3366ff;">BLUE</span></strong> stuff and edit the <strong><span style="color: #ff0000;">RED</span></strong> stuff to fit you needs.</p>
<h3>Getting started:</h3>
<p>Every good system starts with good hardware. The two thinks database servers hunger for are disk space and memory. You should supply your self with as much as you can afford.  Most of my production system run on 32 gig of memory and RAID-10 systems.  Two network ports or more is recommended.  One network port will be used with a crossover cable for the heartbeat function.</p>
<p>To test this installation I&#8217;m building on a VMware server.  If you&#8217;d like to know more about this hardware read my &#8220;Building a Home VMware server&#8221; post.</p>
<h3>Building the Operating System &#8211; DB1</h3>
<p>The operating system I&#8217;m using is CentOS 5.6 64 bit.  You might choose Redhat 6.0. I&#8217;m being conservative and I&#8217;m trying to use free (I have no budget for this project) version of commercial products with enterprise support.</p>
<p>To help you understand the following instructions, for this example, I&#8217;m building a virtual machines (VM) with four (4) virtual SAS hard disks. I have split the four 15G virtual disks into four partitions.  The /boot and /tmp partitions are RAID-1 and the / (root) and /data partitions are RAID-5.  The sizes of these partitions depend you your needs but your /boot needs to be about 1G and the / needs to be about 12G.  I leave /data unassigned and un-formatted.  My layout looks like this.</p>
<pre>Md0 - /boot    Md1 - /    Md2 – /tmp    Md3 - /data
Disk 0 - 15G    256M    4G    512M    11G
Disk 1 - 15G    256M    4G    512M    11G
Disk 2 - 15G    256M    4G    512M    11G
Disk 3 - 15G    256M    Checksum    512M    Checksum
Total    1G    12G    2G    33G</pre>
<h3>Install the OS:</h3>
<p>Start with a &#8220;minimum installation&#8221; with as few applications installed as possible.   No desktop or server applications are needed.<br />
The first step after the install is to update the installed packages.</p>
<pre><strong># <span style="color: #339966;">yum -y update</span></strong></pre>
<p>Even with a minimum install there is a little clean up.  I remove a few un-needed services like bluetooth, printing and there are a couple of packages we will need latter that where not installed.  It is better to install them now and avoid some dependency issues.  I remove supplied MySQL.</p>
<pre><strong># <span style="color: #339966;">rpm -e bluez-utils</span>
#</strong><strong> <span style="color: #339966;">rpm -e smartmontools</span>
# <span style="color: #339966;">yum -y install ruby</span>
# <span style="color: #339966;">yum -y install perl-DBD-MySQL.x86_64</span>
# <span style="color: #339966;">yum -y install libdbi-dbd-mysql.x86_64</span>
# <span style="color: #339966;">rpm -e mysql --nodeps</span>
# <span style="color: #339966;">chkconfig iptables off</span>
# <span style="color: #339966;">chkconfig ip6tables off</span></strong></pre>
<p>After the OS is install and updated the disk looks like this.</p>
<pre># <span style="color: #339966;">df</span></pre>
<p>Filesystem 1K-blocks  Used Available Use% Mounted on</p>
<pre><strong>/dev/md2   11903664    1394068 9895160  13% / /dev/md3   29995056    176200  28270608 1%  /data /dev/md1   505508      10547   468862   3%  /tmp /dev/md0   256586      22969   220369   10% /boot tmpfs      2037380     0       2037380  0%  /dev/shm</strong></pre>
<h3>Disable Security:</h3>
<p>Because we move the MySQL data directy you will need to disable SELinux or update it.</p>
<p>To disable it, edit /etc/selinux/config and change the SELINUX line to SELINUX=disabled:</p>
<pre><strong># <span style="color: #339966;">vi /etc/selinux/config</span></strong>

SELINUX=disabled
<strong># <span style="color: #339966;">echo 0 &gt;/selinux/enforce</span></strong>
<strong># <span style="color: #339966;">service iptables stop</span>
# <span style="color: #339966;">chkconfig iptables off</span>
# <span style="color: #339966;">service ip6tables stop</span>
# <span style="color: #339966;">chkconfig ip6tables off</span></strong></pre>
<p>If you don’t want to disable To update SELinux for the new data directory you will need to have the the selinux tools installed.</p>
<pre><strong># <span style="color: #339966;">yum -y install policycoreutils</span>
# <span style="color: #339966;">semanage fcontext -a -t mysqld_db_t "/data/mysql(/.*)?"</span>
# <span style="color: #339966;">restorecon -Rv /data/mysql</span></strong></pre>
<p>Network configuration:</p>
<pre><strong># <span style="color: #339966;">vi /etc/hosts</span></strong></pre>
<pre><strong><span style="color: #ff0000;">  192.168.2.22 db.grennan.com db</span>
 <span style="color: #ff0000;"> 192.168.2.23 db1.grennan.com db1</span>
 <span style="color: #ff0000;"> 192.168.2.24 db2.grennan.com db2</span>
 <span style="color: #ff0000;"> 192.168.2.25 db3.grennan.com db3</span></strong></pre>
<h3>Syncing Time:</h3>
<p>Time Singularization is very important to maintaining data. You may want to edit the /etc/ntp.conf file to point to your primary NTP time server. CentOS and Redhat provide time servers for your use. I recommend using pool.ntp.org.</p>
<pre><strong># <span style="color: #339966;">yum install ntp</span>
# <span style="color: #339966;">chkconfig ntpd on</span>
# <span style="color: #339966;">ntpdate 0.pool.ntp.org</span>
# <span style="color: #339966;">service ntpd start</span></strong></pre>
<h3>Building DB2/3</h3>
<p>DB2 will become the hot standby server (drbd / heartbeat) and DB3 will  become the MySQL slave server (Tungsten).</p>
<p>If, during the OS install, you created and formatted the /data partition you will need to remove it from /etc/fstab.  On both DB1 and DB2,  edit /etc/fstab and remove the /data file system.</p>
<pre><strong># <span style="color: #339966;">vi /etc/fstab</span></strong>

/dev/md2                /                       ext3    defaults        1 1
/dev/md3                /data                   ext3    defaults        1 2
/dev/md1                /tmp                    ext3    defaults        1 2
/dev/md0                /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
LABEL=SWAP-sdd3         swap                    swap    defaults        0 0
LABEL=SWAP-sdc3         swap                    swap    defaults        0 0
LABEL=SWAP-sdb3         swap                    swap    defaults        0 0
LABEL=SWAP-sda3         swap                    swap    defaults        0 0</pre>
<h3>Setup SSH:</h3>
<pre><strong># <span style="color: #339966;">ssh-keygen -t dsa -f ~/.ssh/id_dsa -N ""</span>
# <span style="color: #339966;">cp ~/.ssh/id_dsa.pub ~/.ssh/authorized_keys</span>
# <span style="color: #339966;">scp -r ~/.ssh db2:</span></strong></pre>
<pre><strong>root@db2's password:</strong></pre>
<pre><strong>  id_dsa.pub               100%  610     0.6KB/s   00:00  id_dsa                   100%  668     0.7KB/s   00:00  authorized_keys       100%  610     0.6KB/s   00:00  known_hosts              100%  398     0.4KB/s   00:00</strong></pre>
<h3>Visualization</h3>
<p>I can&#8217;t stand the color choices made for BASH so I set my own.</p>
<pre><strong>#<span style="color: #339966;"> vi ~/.bash_profile</span></strong>

<span style="color: #3366ff;">export LS_COLORS='no=00:fi=00:di=00;33:ln=00;36:pi=40;33:so=00;35:bd=40;33; \
 01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00; \
 32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00; \
 31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00; \
 31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00; \
 35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:'</span></pre>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F%3Fp%3D556&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=The Full Monty - CentOS 5.5, drbd, PaceMaker, MySQL, Tunsten Replication and more - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/?feed=rss2&#038;p=556</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PostGIS 1.5 in Postgresql 9.0 install on CentOS 5.6</title>
		<link>http://www.mysqlfanboy.com/?p=621</link>
		<comments>http://www.mysqlfanboy.com/?p=621#comments</comments>
		<pubDate>Thu, 14 Jul 2011 19:33:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[HOW TO]]></category>
		<category><![CDATA[PostGIS]]></category>
		<category><![CDATA[Postgresql]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=621</guid>
		<description><![CDATA[I love short and consist install instructions. I know this is a MySQL blog but our good friend PostGreSQL has a great GIS library. This is what I learned upgrading our PostGIS system to GIS 1.5. Much thanks to Jeremy Tunnell for give this document it’s start. Start with CentOS 5.6 x86_64 basic install. Add [...]]]></description>
			<content:encoded><![CDATA[<p>I love short and consist install instructions. I know this is a MySQL blog but our good friend PostGreSQL has a great GIS library. This is what I learned upgrading our PostGIS system to GIS 1.5. Much thanks to Jeremy Tunnell for give this document it’s start.</p>
<p>Start with CentOS 5.6 x86_64 basic install.</p>
<p>Add the PostgreSQL Yum repository to your system.</p>
<pre> $ wget http://yum.pgrpms.org/reporpms/9.0/pgdg-centos-9.0-2.noarch.rpm
 $ rpm -i pgdg-centos-9.0-2.noarch.rpm</pre>
<p>Another location for these is DAG. I have to tried these so your results may very.</p>
<p>You will need to exclude the packages CentOS provide by added two lines to the BASE and UPDATE sections of /etc/yum.repos.d/CentOS-Base.repo. They are:</p>
<pre>exclude=postgresql*
exclude=geos*</pre>
<p>You you are ready to install the needed packages. This includes proj version 4 and geos version 3.</p>
<pre> $ yum install postgresql90-contrib.x86_64
 $ yum install postgis90.x86_64
 $ yum install postgresql90-server
 $ yum install proj
 $ yum install geos
 $ yum install php-pear
 $ yum install php-devel</pre>
<h3>GEOS</h3>
<p>There may be some dependencies you will have to work through. If you are using PDO and haven’t installed the pgsql PDO drivers, you can do it now:</p>
<pre> $ pecl install pdo_pgsql</pre>
<h3>PL/pgSQL</h3>
<p>You you are ready to initialize the database files and start postgresql.</p>
<pre> $ service postgresql-9.0 initdb
 $ service postgresql-9.0 start</pre>
<p>Now you can change to the postgres user and begin installing the functions for GIS. You have to start with defining the language.</p>
<pre> $ su – postgres
 $ psql
 # create language plpgsql ;
 # \q</pre>
<p>Now you can create your database and add the GIS functions calls to it.</p>
<pre> $ createdb geos
 $ psql -d geos -f /usr/pgsql-9.0/share/contrib/postgis-1.5/postgis.sql
 $ psql -d geos -f /usr/pgsql-9.0/share/contrib/postgis-1.5/spatial_ref_sys.sql</pre>
<p>You you can verify the install.</p>
<pre> $ psql geos
 # select postgis_full_version();
                                              postgis_full_version
——————————————————————————————————–
 POSTGIS=”1.5.2″ GEOS=”3.2.2-CAPI-1.6.2″ PROJ=”Rel. 4.7.1, 23 September 2009″ LIBXML=”2.6.26″ USE_STATS
(1 row)</pre>
<p>For more on using PostGIS check out Jeremy’s “PostGIS part 2”.</p>
<p><img src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" />.</p>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F%3Fp%3D621&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=PostGIS 1.5 in Postgresql 9.0 install on CentOS 5.6 - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/?feed=rss2&#038;p=621</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>automysqlbackup 2.5.5</title>
		<link>http://www.mysqlfanboy.com/?p=618</link>
		<comments>http://www.mysqlfanboy.com/?p=618#comments</comments>
		<pubDate>Tue, 12 Jul 2011 21:48:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[automsyqlbackup]]></category>
		<category><![CDATA[Backup]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=618</guid>
		<description><![CDATA[I spent my day doing updates to the automysqlbackup script.  Here is some of what I&#8217;ve added over the last year. The bug number fixes are from SourceForge.  https://sourceforge.net/tracker/?atid=628964&#38;group_id=101066&#38;func=browse # 2.5.5 MTG &#8211; (2011-07-21) #    &#8211; Bug &#8211; Typo Ureadable Unreadable config file line 424 &#8211; ID: 3316825 #    &#8211; Bug &#8211; Change &#8220;#!/bin/bash&#8221; to [...]]]></description>
			<content:encoded><![CDATA[<p>I spent my day doing updates to the automysqlbackup script.  Here is some of what I&#8217;ve added over the last year.</p>
<p>The bug number fixes are from SourceForge. <a href="https://sourceforge.net/tracker/?atid=628964&amp;group_id=101066&amp;func=browse"> https://sourceforge.net/tracker/?atid=628964&amp;group_id=101066&amp;func=browse</a></p>
<p># 2.5.5 MTG &#8211; (2011-07-21)<br />
#    &#8211; Bug &#8211; Typo Ureadable Unreadable config file line 424 &#8211; ID: 3316825<br />
#    &#8211; Bug &#8211; Change &#8220;#!/bin/bash&#8221; to &#8220;#!/usr/bin/env bash&#8221; &#8211; ID: 3292873<br />
#    &#8211; Bug &#8211; problem with excludes &#8211; ID: 3169562<br />
#    &#8211; Bug &#8211; Total disk space on symbolic links &#8211; ID: 3064547<br />
#    &#8211; Added DEBUG option to only print the commands that will be executed.<br />
#    &#8211; Bug &#8211; WHICH command didn&#8217;t work if there was a WHICH alias.<br />
# VER 2.5.4: MTG &#8211; (2011-01-28)<br />
#    &#8211; fixed bug in rsync process.<br />
#    &#8211; Added the ability to backup only a single table by naming the table like<br />
#      database.table<br />
# VER 2.5.2-02:  MTG &#8211; (2010-12-29)<br />
#    &#8211; Added file promission settings (chmod) to directory and file creation points.<br />
# VER 2.5.2-01:  MTG &#8211; (2010-11-06)<br />
#    &#8211; Added &#8216;-R&#8217; to the mysqldump options to include stored procedures in the backup<br />
#      by default. (suggested by Zack Evans)<br />
# VER 2.5.2:  MTG &#8211; (2010-11-04)<br />
#    &#8211; Added option to archive (rsync) the local backup files to a remote locations<br />
#      using the COPYDIR varaible.<br />
#    &#8211; Added option to copy files into a directory based on the hostname using the<br />
#      variable HOSTNAME.  This allows the script to be run from a shared storage directory<br />
#      ( SBM, NFS, NetApp) the data to be kept seperate places.<br />
#    &#8211; Added option to backup all database schemas only using variable FULLSCHEMA.<br />
#    &#8211; Added option to backup MySQL configuration file, my.cnf and remove files older then seven<br />
#      days from the BACKUPDIR directory.<br />
#    &#8211; Added &#8211;master-data=2 and &#8211;single-transaction to include a comment with the master server&#8217;s<br />
#      the binary log coordinates. If used the CHANGE_MASTER_TO line must be uncommented.</p>
<p>The project is at <a href="https://sourceforge.net/projects/automysqlbackup/">https://sourceforge.net/projects/automysqlbackup/</a></p>
<p>You can download my version at <a href="/Files/automysqlbackup.sh">http://www.mysqlfanboy.com/Files/automysqlbackup.sh</a></p>
<p>Email me or leave a comment if you have any trouble.</p>
<p><img class="alignleft" src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></p>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F%3Fp%3D618&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=automysqlbackup 2.5.5 - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/?feed=rss2&#038;p=618</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What is this MySQL file used for?</title>
		<link>http://www.mysqlfanboy.com/?p=516</link>
		<comments>http://www.mysqlfanboy.com/?p=516#comments</comments>
		<pubDate>Thu, 17 Feb 2011 00:25:42 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[Files]]></category>
		<category><![CDATA[Index]]></category>
		<category><![CDATA[MyISAM]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Table]]></category>
		<category><![CDATA[Tables]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=516</guid>
		<description><![CDATA[MySQL keeps many different files, some contain real data, some contain meta data. Witch ones are important? Witch can your throw away? This is my attempt to create a quick reference of all the files used by MySQL, whats in them, what can you do if they are missing, what can you do with them. [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL  keeps many different files, some contain real data, some contain meta  data. Witch ones are important? Witch can your throw away?</p>
<p>This  is my attempt to create a quick reference of all the files used by  MySQL, whats in them, what can you do if they are missing, what can you  do with them.</p>
<p>When I was working for Dell doing Linux support my first words to a customer where “DO YOU HAVE COMPLETE AND VERIFIED BACKUP?” Make one now before you think about doing anything I suggest here.</p>
<p>You should always try to manage your data through a MySQL client.   If things have gone very bad this may not be possible. MySQL may not  start. If your file system get corrupt you may have missing files.  Sometimes people create other files in the MySQL directory (BAD).  This  should help you understand what is safe to remove.</p>
<p><span id="more-516"></span></p>
<p>Before you try to work with one of these files make sure you have the file permissions set correctly.</p>
<p>This  may not be a complete list of files used my MySQL.  It most certainly  doesn’t describe everything each table is used for. If you know of ways  to replace a missing file or what happens to MySQL when a file is  missing that I haven’t described here, please leave me a comment or  email me.  I’ll update this document and give your a reference.</p>
<h3>my.cnf</h3>
<p>This file alters the default configuration settings. MySQL looks in the /etc directory for my.cnf. You should review this file  to insure you are looking in the right place for all other MySQL files.   MySQL WILL run without it.  If you have trouble getting MySQL to  start, read the error log then try moving are renaming this file.</p>
<p>There are other places MySQL looks for configuration files.</p>
<ul>
<li>
<pre>/etc/my.cnf</pre>
</li>
<li>
<pre>/etc/mysql/my.cnf</pre>
</li>
<li>
<pre>~/my.cnf</pre>
</li>
<li>
<pre>&lt;$MYSQLHOME&gt;/my.cnf</pre>
</li>
<li>
<pre>~/.my.cnf</pre>
</li>
</ul>
<p>MySQL will use only one configuration file if you use <a href="http://dev.mysql.com/doc/refman/5.1/en/option-files.html">DEFAULTS-FILE</a> = /etc/foo.bar.</p>
<h3>mysql &lt;directory&gt;</h3>
<p>This directory contains all your data.  This may not be its name.  On  Linux servers the default location for MySQL files is /var/lib/mysql.   This directory is controlled by the “datadir” variable in your my.cnf file.</p>
<p>Do I need to say, deleting this directory deletes everything?</p>
<h3>mysql/mysql&lt;directory&gt;</h3>
<p>This directory is MySQL&#8217;s database and is inside the directory containing all your data (see above).  All the files in this directory are MyISAM tables for MySQL information like table and column privilages, users, functions and more.  MySQL will not run without this this database.</p>
<p>If you delete this directory, and all the files/tables within, you can recreate a blank set with the MySQL install utility.</p>
<pre style="padding-left: 30px;">mysql_install_db --user=mysql --datadir=/var/lib/mysql</pre>
<p>After running this MySQL will rediscover any database that still exist (directory in the MySQL directory).  You will however have to recreate all users, permissions, functions, events, processes, and maybe more.</p>
<h3>ibdata1</h3>
<p>If your remove this file your InnoDB DATA IS GONE and MySQL will recreate an empty file.</p>
<p>If  you are not using the innodb_file_per_table option (default), this file  holds almost ALL of your data in InnoDB tables.  This file is all but  useless without its corresponding  ‘.frm’ file for each table in the  right database directory. If all you have is the .frm files you can  recreate the structure of your tables. (See below.)</p>
<p>Idbdata1  can get really big. The default size is 10MB. MySQL will automatically  extended it by the default size as needed. If MySQL crashed, some of  your InnoDB data may be in your transaction logs (ib_logfile.*).</p>
<p>By design the InnoDB file does not shrink. The <a href="http://vdachev.net/2007/02/22/mysql-reducing-ibdata1/">safest way to shrink</a> this file is to take a complete backup, stop MySQL, remove the ib* files, start MySQL and restore all your data.  REALLY.</p>
<h3>DatabaseName &lt;directory in mysql&gt;</h3>
<p>Each  MySQL database has a directory named after it.  Each directory holds  the meta data for the database. Your MyISAM data is in this directory.  InnoDB tables may be here if the innodb_file_per_table variable is used.  By default InnoDB tables are in the ibdata1 file (see above).</p>
<p>If  you delete the directory your data may be gone. MyISAM data WILL be  lost.  InnoDB tables may still be in the ibdata1.  If so, you will need  to recreate the meta data files to recover your data.</p>
<p>Creating  a directory is almost equivalent to ‘create database’.  If a directory  exists MySQL will show you have a database by that name. The create  database command may also creates a db.opt file.</p>
<h3>&lt;TableName&gt;.frm</h3>
<p>This file is key  to both InnoDB and MyISAM databases. It is the meta data to the  location of your data. It contains the table column definitions.</p>
<p>If  you remove this file MySQL will tell you your DATA doesn’t exist.  It  does. Your data is still in the ibdata (.ibd) file or the ibdata1 file.  You need to recreate the table to recreate this file. If you don’t know  the exact structure of this table your out of luck.</p>
<p>Stop  MySQL and move the .MYD and .MYI files to another directory.  (You  might also make a backup copy.) Start MySQL and recreate this table.  Stop MySQL and copy the .MYD and .MYI files back to the database  directory and restart MySQL.</p>
<h3>&lt;TableName&gt;.MYD</h3>
<p>THIS IS YOUR MyISAM DATA.  If this is all you have, and you know the data structure of the the  table, all is not lost.  (See .frm Above.)  You may also need to  recreate the .MYI index file.</p>
<h3>&lt;TableName&gt;.MYI</h3>
<p>This  file contains the indexs for your table.  If it becomes corrupt or is  deleted you can recreate it using the ‘REPAIR TABLE table_name USE_FRM;’  command.</p>
<h3>/tmp/#&lt;TableName&gt;.[ frm MYD MYI ]</h3>
<p>MySQL creates temporary files in the /tmp director (C:\windows\temp) when sorting (<span style="color: #339966;"><code>ORDER BY</code></span> or <span style="color: #339966;"><code>GROUP           BY</code></span>).  It also creates temp files on a replication server when  the <span style="color: #339966;">LOAD DATA LOCAL INFILE&#8230;</span> command is used. Replication will fail if these files are removed.</p>
<h3>&lt;TableName&gt;.ibd</h3>
<p>THIS IS YOUR InnoDB DATA. If  this is all you have, and you know the data structure of the the table,  all is not lost.  (See .frm Above.) Unlike MyISAM tables the indexes  are contained in this file with your data.</p>
<p>MySQL doesn’t create this file unless you are using the innodb_file_per_table option.</p>
<p>If you have a &#8220;Clean&#8221; .ibd file you can import it into a database with the command &#8220;ALTER TABLE <em><code>tbl_name</code></em> IMPORT TABLESPACE;&#8221;</p>
<h3>&lt;TableName&gt;.CSV</h3>
<p>THIS IS YOUR CSV DATA.  This file contains comma separated text data. These file do not have indexes.</p>
<h3>&lt;TableName&gt;.CSM</h3>
<p>This  file contains meta data for CSV and archive tables.  I have not found  what is stored here. I do know it tells MySQL if you are logging to the  general logs.</p>
<h3>ib_logfile*</h3>
<p>This file contains your un-committed transactions data. MySQL uses it to recover from a crash.</p>
<p>If you shut down InnoDB cleanly, you can remove them. MySQL will recreate them.</p>
<p>If  you change the size of innodb_log_file_size, you will need to recreate  these files by stopping MySQL cleanly and deleting them.</p>
<h3>mysql-bin.*</h3>
<p>This “<a href="http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log#High-Level_Binary_Log_Structure_and_Contents">Bin Log</a>”  files contain any change made to any database. Each transaction is  assigned a MASTER_LOG_POS(ion).  These files are not created by default.  They are used for <a href="http://dev.mysql.com/doc/refman/5.1/en/replication-howto.html">replication</a> and point-in-time recovery.</p>
<p>You  can stop the server and remove these files IF you remove the  mysql-bin.index file as well.  MySQL creates a new bin log file each  time it starts or the logs are flushed.  Deleting these files will the  server is running will break replication.</p>
<h3>mysql-bin.index</h3>
<p>This file is used by MySQL to keep a Bin Log list.  It is a simple text file like;</p>
<p style="padding-left: 30px;">./mysql-bin.000001</p>
<p style="padding-left: 30px;">./mysql-bin.000002</p>
<p style="padding-left: 30px;">./mysql-bin.000003</p>
<p>If  you remove this file, MySQL will recreate it with only the newest bin  log name. If you need to remove old bin logs use the command “purge binary logs [to mysql-bin.######] [before “yyyy-mm-dd”]”.</p>
<p>You can control the number of bin logs using the expire_logs_days variable.</p>
<h3>mysqld.log</h3>
<p>This is MySQL’s primary <a href="http://dev.mysql.com/doc/refman/5.1/en/log-file-maintenance.html">administration log</a>.  MySQL reports starts and stops as well as some warning and errors in  this file.  If MySQL crashes, mysqld_safe will restart it. This log will  report this.</p>
<p>You can delete this file if needed.</p>
<h3>slow.log</h3>
<p>The <a href="http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html">slow query log</a> consists of all SQL statements that took more than<a href="http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_long_query_time"> long_query_time</a> seconds to execute and (as of MySQL 5.1.21) required at least<a href="http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_min_examined_row_limit"> min_examined_row_limit</a> rows to be examined.</p>
<p>You can delete this file if needed.</p>
<h3>db.opt</h3>
<p>Database  characteristics, like the CHARACTER SET clause are stored in the db.opt  file. You may have strange query results if this file is missing. MySQL  will use it’s default. You can recreate this file my altering the table  with the correct settings.</p>
<h3>mysql.pid</h3>
<p>The <a href="http://dev.mysql.com/doc/refman/5.1/en/mysql-server.html">PID file</a> hold the process ID number for the running server. MySQL creates this  file and scripts that start and stop MySQL use it to control MySQL.</p>
<p>MySQL  will remove this file when is stops. You should not delete it if MySQL  is running. If mysql is NOT running and the file exists MySQL may have  crashed and you should delete this file.</p>
<h3>master.info<br />
relay-log.info</h3>
<p>These are found only on the slave servers. Slaves read the commands from those files in order to replicate what the master has done. Simularly to the bin log, it will create files with numbered extensions as needed.</p>
<p>Master.info is a simple text file. This is a store of the master command is used by mysql when it restarts to make the slave connection.</p>
<pre style="padding-left: 30px;">15
mysql-bin.006004
1006945586
192.168.1.2
repl_user
P@sSw0Rd
3306
60
0</pre>
<p>Removing these files will breat replication and / or through your slave out of sync.</p>
<h3>*relay-bin.index</h3>
<p>The &#8220;*&#8221; is either the hostname or the same as the .PID file.  This file is the index for the relay log used in replication.  Relay bin files are found only on slave servers.</p>
<h3>&lt;TableName&gt;.TRG</h3>
<p>Contains the list of triggers belonging to a given table</p>
<h3>&lt;TrigerName&gt;.TRN</h3>
<p>Contains some metadata on the trigger</p>
<h3>&lt;TableName&gt;.ARZ</h3>
<p>It’s the file containing the data for an ARCHIVE table.</p>
<h3>&lt;TableName&gt;.par</h3>
<p>Contains the definition of a partition</p>
<p>tablename#P#partitionname.{MYD,ARZ,ibd}<br />
contains the data related to a given partition</p>
<p><img class="alignnone" src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></p>
<h6>References:</h6>
<p>FULL DISK<br />
<a href="http://dev.mysql.com/doc/refman/5.1/en/full-disk.html">http://dev.mysql.com/doc/refman/5.1/en/full-disk.html</a></p>
<p>MySQL Database Backup .MYI and .MYD<br />
<a href="http://www.aeonity.com/frost/mysql-database-backup-myi-myd">http://www.aeonity.com/frost/mysql-database-backup-myi-myd</a></p>
<p>Recovering from Crashes<br />
<a href="http://dev.mysql.com/tech-resources/articles/recovering-from-crashes.html">http://dev.mysql.com/tech-resources/articles/recovering-from-crashes.html</a></p>
<p>Using Per-Table Tablespaces<a href="http://dev.mysql.com/doc/refman/5.0/en/innodb-multiple-tablespaces.html"></p>
<p>http://dev.mysql.com/doc/refman/5.0/en/innodb-multiple-tablespaces.html</a></p>
<p>Troubleshooting <code>InnoDB</code> Data Dictionary Operations<br />
<a href="http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting-datadict.html">http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting-datadict.html</a></p>
<p><cite><strong>Giuseppe Maxia</strong> &#8211; who writes a great blog about mysql at<a href="http://datacharmer.blogspot.com/"> </a></cite><a href="http://datacharmer.blogspot.com/">http://datacharmer.blogspot.com/</a> contributed several files I missed.<a rel="external nofollow" href="http://datacharmer.blogspot.com/"><br />
</a></p>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F%3Fp%3D516&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=What is this MySQL file used for? - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/?feed=rss2&#038;p=516</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Update to AutoMySQLBackup.sh</title>
		<link>http://www.mysqlfanboy.com/?p=508</link>
		<comments>http://www.mysqlfanboy.com/?p=508#comments</comments>
		<pubDate>Fri, 28 Jan 2011 21:17:45 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[Commentary]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=508</guid>
		<description><![CDATA[For a long time I though the AutoMySQLBackup project had died.  Then, after I created many updates, in November of last year I saw some life. Meanwhile, I have continued to update the code and track what people have requested.   Low volume project are sometimes hard to keep alive. People think the project is dead [...]]]></description>
			<content:encoded><![CDATA[<p>For a long time I though the <a href="https://sourceforge.net/projects/automysqlbackup/">AutoMySQLBackup</a> project had died.  Then, after I created many updates, in November of last year I saw some life. Meanwhile, I have continued to update the code and track what people have requested.   Low volume project are sometimes hard to keep alive. People think the project is dead and don&#8217;t want to use code that will not see updates.  Then if you make updates the authors may not come alive often enough to make the changes.</p>
<p>I have updated AutoMySQLBackup again. This time I have included the ability to make backups at the table level by including the table name, with the database name, in the list of databases to be backed up.  Adding a &#8216;.&#8217; between the database name and the table name (data.table) will backup only that table in the database.  (IE DBNAME=&#8221;mysql test database.table&#8221;)</p>
<p>You can download my version here.  <a href="../Files/automysqlbackup.sh">automysqlbackup.sh</a>.</p>
<p>Some of my improvements include:</p>
<ul>
<li>copy (rsync) the local backup files to a remote locations using the COPYDIR variable.</li>
<li>option to copy files into a directory based on the host name using the variable HOSTNAME.  This allows the script to be run from a shared storage directory ( SBM, NFS, NetApp) the data to be kept separate.</li>
<li>option to backup the full schema only using variable FULLSCHEMA.</li>
<li>option to backup MySQL configuration file, my.cnf</li>
<li>remove files older then seven days from the BACKUPDIR directory.</li>
<li>Added –master-data=2 and –single-transaction to include a replication information as a comment</li>
<li>The ability to backup a single table in a database.</li>
</ul>
<p><img class="alignnone" src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></p>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F%3Fp%3D508&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=Update to AutoMySQLBackup.sh - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/?feed=rss2&#038;p=508</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>It&#8217;s about Time.</title>
		<link>http://www.mysqlfanboy.com/?p=301</link>
		<comments>http://www.mysqlfanboy.com/?p=301#comments</comments>
		<pubDate>Thu, 27 Jan 2011 21:08:27 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[Commentary]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Tunning]]></category>
		<category><![CDATA[Caching]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=301</guid>
		<description><![CDATA[WHAT TIME IS IT? This post started with a simple question: &#8220;Does the function NOW() get executed every time a row is examined?&#8221; According to the manual,  &#8220;Functions that return the current date or time each are evaluated only once per query &#8230;. multiple references to a function such as NOW() &#8230; produce the same [...]]]></description>
			<content:encoded><![CDATA[<h3>WHAT TIME IS IT?</h3>
<p>This post started with a simple question: &#8220;Does the function NOW() get executed every time a row is examined?&#8221; According to the manual,  <em>&#8220;Functions  that return the current date or time each are evaluated only once per  query &#8230;. multiple references to a function such as NOW() &#8230; produce  the same result. &#8230;. (However,) as of MySQL 5.0.12, SYSDATE()  returns  the time (the row is) executes. &#8220;</em></p>
<ul>
<li><strong>CURDATE()</strong> returns the current date.</li>
<li><strong>CURTIME()</strong> returns the current time.</li>
<li><strong>UTC_DATE()</strong> returns the current UTC date.</li>
<li><strong>UTC_TIME()</strong> returns the current UTC time.</li>
<li><strong>NOW()</strong> return the current date and time.</li>
<li><strong>UTC_TIMESTAMP()</strong> returns the current UTC date and time.</li>
<li><strong>SYSDATE()</strong> returns the date and time at which the function executes.</li>
<li><strong>LOCALTIME(), LOCALTIME(), LOCALTIMESTAMP(), LOCALTIMESTAMP()</strong> are synonyms for NOW().</li>
</ul>
<p>All these functions return some value of a date / time. For example, WEEK() returns the week number for <em>date</em>.</p>
<p>Here is an example of a common query.</p>
<pre style="padding-left: 30px;">SELECT  stn, temp, lat, lon WHERE valid_time &gt; NOW() – INTERVAL 1 HOUR;</pre>
<p>This is the right way to make this query because NOW() is only executed once.  If  SYSDATE() was used, each row selected would call SYSDATE().</p>
<p>So, if NOW() is only executed once and SYSDATE() is executed every time, we should see this difference if we BENCHMARK these functions.</p>
<pre style="padding-left: 30px;">mysql&gt; SELECT BENCHMARK( 10000000, NOW() );
+------------------------------+
| BENCHMARK( 10000000, NOW() ) |
+------------------------------+
|                            0 |
+------------------------------+
1 row in set (<strong><span style="color: #ff0000;">0.07 sec</span></strong>)

+----------------------------------+
| BENCHMARK( 10000000, SYSDATE() ) |
+----------------------------------+
|                                0 |
+----------------------------------+
1 row in set (<strong><span style="color: #ff0000;">5.49 sec</span></strong>)</pre>
<p>And it seems to be true.  But what about real SQL statements. Will this hold up? Here is a simple table.</p>
<pre style="padding-left: 30px;">CREATE TABLE `TableName1` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `datetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 PRIMARY KEY (`id`)
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1</pre>
<p>I used this SQL statement to put records in the table. It adds a new records with a new date/time with each query. Like:</p>
<pre style="padding-left: 30px;">INSERT INTO `stage`.`TableName1`(`id`,`dtime`) VALUES ( NULL,NOW())</pre>
<p>What if we then query the table every second.  Will NOW() be processed as a part of the results?  I used the SLEEP() function to delay each record.</p>
<pre style="padding-left: 30px;">SELECT id, dtime, (SELECT NOW()) FROM TableName1 WHERE NOT SLEEP(1);</pre>
<p>This query took ten seconds to run for a table with ten rows and returns these results.</p>
<pre style="padding-left: 30px;">id	dtime	                (SELECT NOW())
 1	2010-08-06 15:55:57	2010-08-06 16:05:06
 2	2010-08-06 15:56:12	2010-08-06 16:05:06
 3	2010-08-06 15:56:16	2010-08-06 16:05:06
 4	2010-08-06 15:56:20	2010-08-06 16:05:06
 5	2010-08-06 15:56:30	2010-08-06 16:05:06
 6	2010-08-06 16:48:23	2010-08-06 16:05:06
 7	2010-08-06 16:48:26	2010-08-06 16:05:06
 8	2010-08-06 16:48:27	2010-08-06 16:05:06
 9	2010-08-06 16:48:28	2010-08-06 16:05:06
 10	2010-08-06 16:48:29	2010-08-06 16:05:06</pre>
<p>As the documentation states, the NOW() is NOT processes every time.</p>
<p>What if  NOW() is a part of a JOIN?</p>
<pre style="padding-left: 30px;">SELECT t.id, t.dtime, d.n  FROM TableName1 AS t, (SELECT 1, NOW() AS n) AS d  WHERE NOT SLEEP(1);</pre>
<p>Again, this SELECT takes ten seconds to run for a table with ten rows.</p>
<pre style="padding-left: 30px;">id	dtime                 	n
 1	2010-08-06 15:55:57	2010-08-06 17:09:00
 2	2010-08-06 15:56:12	2010-08-06 17:09:00
 3	2010-08-06 15:56:16	2010-08-06 17:09:00
 4	2010-08-06 15:56:20	2010-08-06 17:09:00
 5	2010-08-06 15:56:30	2010-08-06 17:09:00
 6	2010-08-06 16:48:23	2010-08-06 17:09:00
 7	2010-08-06 16:48:26	2010-08-06 17:09:00
 8	2010-08-06 16:48:27	2010-08-06 17:09:00
 9	2010-08-06 16:48:28	2010-08-06 17:09:00
 10	2010-08-06 16:48:29	2010-08-06 17:09:00</pre>
<p>And again the NOW() function is only executed once.</p>
<p>The WHERE clause is harder to test. I inserted a row in the table only seconds apart. I then quickly ran the SELECT again to see if the NOW() matched the times in the table.</p>
<pre style="padding-left: 30px;">SELECT t.id, t.dtime FROM TableName1 AS t WHERE NOT SLEEP(1) AND dtime = (SELECT NOW() - INTERVAL 15 SECOND)  ;</pre>
<p>Here is the data table.</p>
<pre style="padding-left: 30px;">id	dtime
 1	2010-08-06 17:35:00
 2	2010-08-06 17:35:00
 3	2010-08-06 17:35:01
 4	2010-08-06 17:35:03
 5	2010-08-06 17:35:04
 6	2010-08-06 17:35:04
 7	2010-08-06 17:35:04
 8	2010-08-06 17:35:05
 9	2010-08-06 17:35:05
 10	2010-08-06 17:35:05
 11	2010-08-06 17:35:06
 12	2010-08-06 17:35:06
 13	2010-08-06 17:35:06
 14	2010-08-06 17:35:07
 15	2010-08-06 17:35:07
 16	2010-08-06 17:35:07
 17	2010-08-06 17:35:08
 18	2010-08-06 17:35:08
 19	2010-08-06 17:35:08
 20	2010-08-06 17:35:09
 21	2010-08-06 17:35:09
 22	2010-08-06 17:35:09
 23	2010-08-06 17:35:09
 24	2010-08-06 17:35:10
 25	2010-08-06 17:35:10</pre>
<p>The select statement above only took three seconds to run and returned three rows all the same.</p>
<pre style="padding-left: 30px;"> id	dtime
 11	2010-08-06 17:35:06
 12	2010-08-06 17:35:06
 13	2010-08-06 17:35:06</pre>
<p>MySQL is evaluating dtime = (SELECT NOW() &#8211; INTERVAL 15 SECOND) before the SLEEP(1).   MySQL only ran the SLEEP(1) for each record that matched.  I reversed the two parts of the AND and   the order of the didn&#8217;t matter.</p>
<p>Next I tried these functions with SYSDATE().  I found it is executed every time it is evaluated.  This SELECT took 17 seconds and return a different time for each.</p>
<pre style="padding-left: 30px;">SELECT id, dtime, (SELECT SYSDATE()) FROM TableName1 WHERE NOT SLEEP(1);</pre>
<pre style="padding-left: 30px;">id    dtime                 (SELECT SYSDATE())
1    2010-08-06 18:28:42    2010-08-06 19:00:57
2    2010-08-06 18:28:42    2010-08-06 19:00:58
3    2010-08-06 18:28:42    2010-08-06 19:00:59
4    2010-08-06 18:28:43    2010-08-06 19:01:00
5    2010-08-06 18:28:43    2010-08-06 19:01:01
6    2010-08-06 18:28:43    2010-08-06 19:01:02
7    2010-08-06 18:28:43    2010-08-06 19:01:03
8    2010-08-06 18:28:44    2010-08-06 19:01:04
9    2010-08-06 18:28:44    2010-08-06 19:01:05
10    2010-08-06 18:28:44    2010-08-06 19:01:06
11    2010-08-06 18:28:44    2010-08-06 19:01:07
12    2010-08-06 18:28:45    2010-08-06 19:01:08
13    2010-08-06 18:28:45    2010-08-06 19:01:09
14    2010-08-06 18:28:45    2010-08-06 19:01:10
15    2010-08-06 18:28:45    2010-08-06 19:01:11
16    2010-08-06 18:28:46    2010-08-06 19:01:12
17    2010-08-06 18:28:46    2010-08-06 19:01:13</pre>
<p>The SET TIMESTAMP statement affects the value returned by NOW() but not by SYSDATE(). This means that timestamp settings in the binary log have no effect on invocations of SYSDATE().</p>
<h3>CACHING</h3>
<p>MySQL doesn&#8217;t cache nondeterministic functions like NOW() and SYSDATE().  If your application processes the same data base queries within the same second or if you need the two queries to return the same results, you will need to turn NOW() into a string.</p>
<p style="padding-left: 30px;">SELECT stn, temp, lat, lon WHERE valid_time &gt; ‘2010-05-06 23:20:00’ – INTERVAL 1 HOUR;</p>
<p>Even better, do the math in your program.  Here are some benchmarks show this outcome.</p>
<p style="padding-left: 30px;">SELECT stn, temp, lat, lon WHERE valid_time &gt; ‘2010-05-06 22:20:00’;</p>
<pre style="padding-left: 30px;">+------------------------------------------------------------------------+
| BENCHMARK( 10000000, NOW() -  INTERVAL 1 HOUR = '2011-01-27 19:00:00') |
+------------------------------------------------------------------------+
|                                                                      0 |
+------------------------------------------------------------------------+
1 row in set (<strong><span style="color: #ff0000;">0.36 sec</span></strong>)

mysql&gt; SELECT BENCHMARK( 10000000, SYSDATE() -  INTERVAL 1 HOUR = '2011-01-27 19:00:00');
+----------------------------------------------------------------------------+
| BENCHMARK( 10000000, SYSDATE() -  INTERVAL 1 HOUR = '2011-01-27 19:00:00') |
+----------------------------------------------------------------------------+
|                                                                          0 |
+----------------------------------------------------------------------------+
1 row in set (<strong><span style="color: #ff0000;">2.42 sec</span></strong>)

mysql&gt; SELECT BENCHMARK( 10000000, '2010-05-06 23:20:00' -  INTERVAL 1 HOUR = '2011-01-27 19:00:00');
+----------------------------------------------------------------------------------------+
| BENCHMARK( 10000000, '2010-05-06 23:20:00' -  INTERVAL 1 HOUR = '2011-01-27 19:00:00') |
+----------------------------------------------------------------------------------------+
|                                                                                      0 |
+----------------------------------------------------------------------------------------+
1 row in set (<strong><span style="color: #ff0000;">3.98 sec</span></strong>)

mysql&gt; SELECT BENCHMARK( 10000000, '2010-05-06 23:20:00' = '2011-01-27 19:00:00');
+---------------------------------------------------------------------+
| BENCHMARK( 10000000, '2010-05-06 23:20:00' = '2011-01-27 19:00:00') |
+---------------------------------------------------------------------+
|                                                                   0 |
+---------------------------------------------------------------------+
1 row in set (<strong><span style="color: #ff0000;">0.22 sec</span></strong>)</pre>
<p>REFERENCE:</p>
<p>http://dev.mysql.com/doc/refman/5.0/en/functions.html</p>
<p>http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html</p>
<p><img class="alignnone" src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></p>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F%3Fp%3D301&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=It's about Time. - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/?feed=rss2&#038;p=301</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>HandlerSocket plugin &#8211; NoSQL/SQL interactions</title>
		<link>http://www.mysqlfanboy.com/?p=483</link>
		<comments>http://www.mysqlfanboy.com/?p=483#comments</comments>
		<pubDate>Tue, 28 Dec 2010 20:35:29 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Commentary]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[MariaDB]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=483</guid>
		<description><![CDATA[HandlerSocket is cool. But, it turns out there are a few issues. Justin Swanhart points out HandlerSocket currently lacks atomic operations . Since HandlerSocket uses different connections for reading and writing, you can&#8217;t increment/decrement a value without creating a race condition. Still, the idea of skipping SQL interpretation and just reading the data you know [...]]]></description>
			<content:encoded><![CDATA[<p>HandlerSocket is cool. But, it turns out there are a few issues.</p>
<p><a href="http://swanhart.livejournal.com/">Justin Swanhart</a> points out HandlerSocket currently <a href="https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL/issues#issue/27">lacks atomic operations </a>. Since HandlerSocket uses different connections for reading and  writing, you can&#8217;t increment/decrement a value without creating a  race condition.</p>
<p>Still, the idea of skipping SQL interpretation and just reading the data you know you want is a great one.  Writing data might even be better. But being able to use both SQL and NoSQL could be really wonderful.  What if we could use complex queries to update complex tables and pluck values out as needed.  For example, queries to analyze current weather conditions and produce forecasts that we could then retrieve via a location key? What about updating current condition data via NoSQL before running the analysis?  Will this work?</p>
<h3><strong>NoSQL writes (insert/update/delete) and SQL reads</strong></h3>
<p>Using the PHP test program from my last post, I&#8217;ve tried inserting and updating data via NoSQL and reading it back via SQL.  What I found was not good.  NoSQL is consistent.  If I write data via NoSQL I always get back my data via NoSQL.  However, if I try to write data via NoSQL and read it with a  simple &#8216;Select * from user;&#8217;  I get inconsistent results.</p>
<p>There is what the record looked like.</p>
<pre>MariaDB [test]&gt; select * from user where user_id = 1;
+---------+-----------+-----------------------+---------------------+
| user_id | user_name | user_email            | created             |
+---------+-----------+-----------------------+---------------------+
|       1 | mark      |                       | 0000-00-00 00:00:00 |
+---------+-----------+-----------------------+---------------------+</pre>
<p>Here is the code segment I used to update  the table. Review my previous posts for more details.</p>
<pre>$hs2 = new HandlerSocket($host, $wport);
if (!($hs2-&gt;openIndex(1, $dbname, $table, '', 'user_id,user_name,user_email,created')))
{
 echo $hs2-&gt;getError(), PHP_EOL;
 die();
}

if (!($hs2-&gt;executeUpdate(1, '=', array('1'), array('1',"Mark",'mark@www.mysqlfanboy.com'), 1, 0)))
{
 echo $hs2-&gt;getError(), PHP_EOL;
 die();
}</pre>
<p>A quick query via NoSQL shows the data has been updated. The &#8216;mark&#8217; is now &#8216;Mark&#8217; and the email address is there.</p>
<pre># <strong><span style="color: #993300;">php mytest.php</span></strong>
data &gt; Mark
array(1) {
 [0]=&gt;
 array(4) {
 [0]=&gt;
 string(1) "1"
 [1]=&gt;
 string(4) "<span style="color: #ff00ff;">M</span>ark"
 [2]=&gt;
 string(20) "<span style="color: #ff00ff;">mark@www.mysqlfanboy.com</span>"
 [3]=&gt;
 string(19) "0000-00-00 00:00:00"
 }
}
</pre>
<p>I found MySQL SQL queries did not return my changes.  I tried many times to write new and updated records without SQL show the results. I thought this was because of query caching so I tried flushing the query cache without effect.  I was worried the date was buffered somewhere but not written to disk.  I restarted MySQL and the data was corrected.</p>
<pre><strong><span style="color: #008000;"><span style="color: #000000;">#</span> <span style="color: #993300;">mysql test</span></span></strong>
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 26457
Server version: 5.1.51-MariaDB-mariadb87-log (MariaDB - http://mariadb.com/)

This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [test]&gt; <span style="color: #993300;">select * from user;</span>
+---------+-----------+-----------------------+---------------------+
| user_id | user_name | user_email            | created             |
+---------+-----------+-----------------------+---------------------+
|       1 | mark      |                       | 0000-00-00 00:00:00 |
|       2 | linda     | linda@www.mysqlfanboy.com | 0000-00-00 00:00:00 |
|       3 | mark      | test@www.mysqlfanboy.com  | NULL                |
|       4 | test      | test@www.mysqlfanboy.com  | 0000-00-00 00:00:00 |
|       5 | foo       | foo@www.mysqlfanboy.com   | 0000-00-00 00:00:00 |
+---------+-----------+-----------------------+---------------------+
5 rows in set (0.00 sec)

MariaDB [test]&gt; <span style="color: #993300;">FLUSH QUERY CACHE;</span>
Query OK, 0 rows affected (0.02 sec)

MariaDB [test]&gt; select * from user;
+---------+-----------+-----------------------+---------------------+
| user_id | user_name | user_email            | created             |
+---------+-----------+-----------------------+---------------------+
|       1 | mark      |                       | 0000-00-00 00:00:00 |
|       2 | linda     | linda@www.mysqlfanboy.com | 0000-00-00 00:00:00 |
|       3 | mark      | test@www.mysqlfanboy.com  | NULL                |
|       4 | test      | test@www.mysqlfanboy.com  | 0000-00-00 00:00:00 |
|       5 | foo       | foo@www.mysqlfanboy.com   | 0000-00-00 00:00:00 |
+---------+-----------+-----------------------+---------------------+
5 rows in set (0.00 sec)

MariaDB [test]&gt; <strong><span style="color: #993300;">quit</span></strong>
Bye
# <strong><span style="color: #993300;">service mysql stop</span></strong>
Shutting down MySQL.                                       [  OK  ]
# <strong><span style="color: #993300;">service mysql start</span></strong>
Starting MySQL.                                            [  OK  ]
# <strong><span style="color: #993300;">mysql test</span></strong>
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 5.1.51-MariaDB-mariadb87-log (MariaDB - http://mariadb.com/)

This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [test]&gt; <strong><span style="color: #993300;">select * from user;</span></strong>
+---------+-----------+-----------------------+---------------------+
| user_id | user_name | user_email            | created             |
+---------+-----------+-----------------------+---------------------+
|       1 | Mark      | mark@www.mysqlfanboy.com  | 0000-00-00 00:00:00 |
|       2 | linda     | linda@www.mysqlfanboy.com | 0000-00-00 00:00:00 |
|       3 | mark      | test@www.mysqlfanboy.com  | NULL                |
|       4 | test      | test@www.mysqlfanboy.com  | 0000-00-00 00:00:00 |
|       5 | foo       | foo@www.mysqlfanboy.com   | 0000-00-00 00:00:00 |
+---------+-----------+-----------------------+---------------------+
5 rows in set (0.00 sec)
</pre>
<h3>MySQL writes and NoSQL reads</h3>
<p>Writing data via MySQL and reading via NoSQL works.  I found no issues with this process.  This leads me to believe the issue is related to write buffering and not query caching.</p>
<h3>Security</h3>
<p>What security.  HandleSocket gives you direct access to EVERY table.  With HandleSocket you can update anything including MySQL security tables.  You would be crazy to use HandleSocket in a public facing system.  Even if you using it in back office process you should use some sort of filewall technology like iptables to limit commectivity.</p>
<p>I&#8217;ll say this again: <span style="color: #ff0000;"><strong>HANDLESOCKET HAS NO SECURITY!</strong></span></p>
<p><span style="color: #ff0000;"><strong><img class="alignnone" src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></strong></span></p>
<p><span style="color: #ff0000;"><strong><br />
</strong></span></p>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F%3Fp%3D483&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=HandlerSocket plugin - NoSQL/SQL interactions - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/?feed=rss2&#038;p=483</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using HandlerSocket Plugin for MySQL with PHP</title>
		<link>http://www.mysqlfanboy.com/?p=476</link>
		<comments>http://www.mysqlfanboy.com/?p=476#comments</comments>
		<pubDate>Tue, 28 Dec 2010 12:00:11 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[HOW TO]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=476</guid>
		<description><![CDATA[This document was updated and tested for CentOS 6.0 In my last two posts I installed the HandlerSocket plugin into MariaDB and showed how to use it with Perl.  That&#8217;s good, but if you are thinking of using HandlerSocket  I&#8217;m guessing you have a very high traffic website and it&#8217;s written in PHP.  In this [...]]]></description>
			<content:encoded><![CDATA[<p><em>This document was updated and tested for CentOS 6.0</em></p>
<p>In my last two posts I installed the HandlerSocket plugin into MariaDB and showed how to use it with Perl.  That&#8217;s good, but if you are thinking of using HandlerSocket  I&#8217;m guessing you have a very high traffic website and it&#8217;s written in PHP.  In this post I&#8217;m going to connect HandlerSocket with PHP.  In the next post I&#8217;ll discuss using HandlerSocket on a production system.</p>
<p>There are a couple of HandlerSocket php modules projects.  I tried each of them and I found <a href="https://code.google.com/p/php-handlersocket/">PHP-HandlerSocket</a> was the best.  Both of them are still rough and neither of them have documentation beyond their source code.  Maybe this will move things forward.</p>
<p>Here are the applications you need to have installed that where not installed in my last two posts.  Run this to check your system.</p>
<pre> yum install php-devel re2c php php-mysql</pre>
<p>Start in the a Downloads directory and wget the newest tarball.</p>
<pre> cd ~
 mkdir Downloads
 cd Downloads
 wget https://php-handlersocket.googlecode.com/files/php-handlersocket-0.3.0.tar.gz
 tar zxf  php-handlersocket-0.2.0.tar.gz</pre>
<p>Compile and install the module.  You may need to install php and php-devel .</p>
<pre> cd php-handlersocket
 phpize
 ./configure
 make
 make test
 make install</pre>
<p>In the &#8216;make test&#8217; step you are looking for <strong>Tests passed    :    1 (100.0%) (100.0%)</strong></p>
<p>With everything in place, you need to teach PHP to load the module my editing the PHP configuration file  and add the extension.</p>
<pre> vi /etc/php.ini</pre>
<p>Search for the <em><strong>Dynamic Extensions</strong></em> section and add this line.</p>
<pre> extension=handlersocket.so</pre>
<p>Run<strong> php</strong> to test that the module is loading correctly.  <strong>If nothing happens, your good.</strong></p>
<p>I had some trouble at the start.   This is bad:</p>
<pre> # php
 PHP Warning:  PHP Startup: Unable to load dynamic library  '/usr/lib64/php/modules/hadlersocket.so'
 -  /usr/lib64/php/modules/hadlersocket.so: cannot open shared object file:
  No such file or directory in Unknown on line 0</pre>
<p>&nbsp;</p>
<p>To do more testing we need a database and some data.  Here is what I created. I&#8217;ve colored the sections of code as they correspond to the output.</p>
<pre>CREATE TABLE `user` (
 `user_id` INT (10) UNSIGNED NOT NULL,
 `user_name` VARCHAR (50),
 `user_email` VARCHAR (255),
 `created` DATETIME DEFAULT NULL,
 PRIMARY KEY (`user_id`),
 KEY `NAME` (`user_name`)
 ) ENGINE = INNODB ;

INSERT INTO `user`  VALUES
 ( 1, 'mark', 'mark@www.mysqlfanboy.com', '0000-00-00 00:00:00' ),
 ( 2, 'linda', 'linda@www.mysqlfanboy.com', '0000-00-00 00:00:00' ),
 ( 3, 'mark', 'test@www.mysqlfanboy.com', NULL ) ;</pre>
<p>I created this program to read this data:  (mytest.php)  HandlerSocket can write data to the database.  I&#8217;ve left writing as an exercise to the reader. (For now.)</p>
<pre>&lt;?php
 $host = 'db';
 $port = 9998;
 $dbname = 'test';
 $table = 'user';
 $index = 'NAME';
 $columns = 'user_id,user_name,user_email,created';

 $hs = new HandlerSocket($host, $port);
 if (!($hs-&gt;openIndex(<strong><span style="color: #ff00ff;">0</span></strong>, $dbname, $table, $index, $columns)))
 {
 echo $hs-&gt;getError(), PHP_EOL;
 die();
 }

 $retval = $hs-&gt;executeSingle(<strong><span style="color: #ff00ff;">0</span></strong>, '=', array('mark'), 10, 0);
 <strong><span style="color: #800000;">echo "data &gt; ",$retval[0][1], " \n";</span></strong>
<strong> <span style="color: #0000ff;">var_dump($retval);</span></strong>

 $retval = $hs-&gt;executeMulti(
 array(array(0, '=', array('mark'), 1, 0),
 array(0, '=', array('linda'), 1, 0)));
 <strong><span style="color: #008000;">var_dump($retval);</span></strong>

 unset($hs);

 ?&gt;</pre>
<p>Here is the output of running mytest.php.</p>
<pre># <strong>php mytest.php</strong>
<span style="color: #800000;"><strong>data &gt; mark</strong> </span>
<span style="color: #0000ff;">array(2) { [0]=&gt; array(4) { [0]=&gt; string(1) "1" [1]=&gt; string(4) "mark" [2]=&gt; string(20) "mark@www.mysqlfanboy.com" [3]=&gt; string(19) "0000-00-00 00:00:00" } [1]=&gt; array(4) { [0]=&gt; string(1) "3" [1]=&gt; string(4) "mark" [2]=&gt; string(20) "test@www.mysqlfanboy.com" [3]=&gt; NULL } }</span>
<span style="color: #008000;">array(2) { [0]=&gt; array(1) { [0]=&gt; array(4) { [0]=&gt; string(1) "1" [1]=&gt; string(4) "mark" [2]=&gt; string(20) "mark@www.mysqlfanboy.com" [3]=&gt; string(19) "0000-00-00 00:00:00" } } [1]=&gt; array(1) { [0]=&gt; array(4) { [0]=&gt; string(1) "2" [1]=&gt; string(5) "linda" [2]=&gt; string(21) "linda@www.mysqlfanboy.com" [3]=&gt; string(19) "0000-00-00 00:00:00" } } } </span><span style="color: #000000;"> </span></pre>
<p>So it works, but do you really want to use it?  There are a lot more to questions to investigate.   Is it writing data any faster then SQL? Is writing faster then a bulk file load?  What if you mix SQL and HandlerSocket calls?  What does buffering do to these processes?</p>
<p>You you have any questions about about what I&#8217;ve written or that you would like be to investigate, email me &#8211; mark @ <a href="http://www.grennan.com">Grennan.com</a>.</p>
<p><img src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></p>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F%3Fp%3D476&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=Using HandlerSocket Plugin for MySQL with PHP - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/?feed=rss2&#038;p=476</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
