title: MySQL comparing two tables rows hash
body: <p>I have two tables one is master table and other is just for cache. From time to time I check whether cache table is up to date and there is no missing data. Cache table is using MyISAM engine and master table is using InnoDB engine.</p>
  
  <p>To explain it in more detail I give you an example</p>
  
  <p>Cache table contains fields from following two tables</p>
  
  <pre><code>product_categories (cat-id, cat_name, parent_cat_id DEFAULT NULL, parent_cat_name DEFAULT NULL) 
  
  products (product_num, product_name, product_desc, price, image, product_date, availability)
  </code></pre>
  
  <p>It may be possible cache table does not contain products or it may contain products data but it may not be accurate.</p>
  
  <p>In this question <a href="https://stackoverflow.com/questions/225772/compare-two-mysql-databases">Compare two MySQL databases</a> a tool Toad for MySQL has mentioned but I want to do it using PHP.</p>
  
  <p>Cache table schema</p>
  
  <pre><code>products_cache | CREATE TABLE `products_cache` (
    `product_num` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `cat_id` int(10) unsigned NOT NULL,
    `parent_cat_id` int(10) unsigned DEFAULT NULL,
    `cat_name` varchar(50) NOT NULL,
    `parent_cat_name` varchar(50) DEFAULT NULL,
    `product_desc` text NOT NULL,
    `price` float(10) unsigned NOT NULL,
    `image` varchar(65) NOT NULL DEFAULT '',
    `product_date` DATE DEFAULT NULL, 
    `availability` tinyint(1) NOT NULL DEFAULT '1',
    PRIMARY KEY (`product_num`),
  ) ENGINE=MyISAM
  </code></pre>
  
  <h2>Possible solution</h2>
  
  <p>Compute the md5 of the fields and store it in cache table and then next time check the md5 in cache table if data is changed. It will work fine except there will be performance issue (I run cache fixer every month, so I think I can compromise with that). Please comment on this.</p>