Edmonds Commerce Logo
  • home
    • blog
  • ecommerce
    • product catalogue
    • order processing
    • customer services
    • stock control
    • human resources
    • management information
  • development
    • oscommerce
    • php
    • mysql
    • open source
    • performance tuning
  • design
  • marketing
  • contact us
    • pricing

Edmonds Commerce Blog

Freelance PHP Ecommerce and SEO Developer in the UK

Latest Posts

CRELoaded Remove Google Ads -
ICECat Integration with osCommerce, Magento etc
Magento UK
PHP Cached Download Function

Most Popular Posts

PHP Email Attachment Function Freelance osCommerce UK Ultimate osCommerce Checkout - Fast and Friendly PHP : Dead Easy Excel Export

MySQL Dump Partial Restore - Split MySQL Dump into Tables

April 9th, 2008
Read More mysql, php

MySQL dumps are often used as a quick and easy way of backing up an entire MySQL database in one go. However, they are only really designed to restore whole databases as well. So what if you only want to restore certain tables?

I have written this nice little PHP script which will take your dump file and split it into lots of little sql files - one for each table. You can then restore which ever tables you want.

Simply create a php file in the same directory as your dump file. Name it something easy to remember. Then go to it in your web browser, input the name of the dump file and click go.

As this is a fairly massive task (depending on the size of your dump file) you may find it works better on your local test server with some generous php_ini settings for max_execution_time etc.

PLAIN TEXT
PHP:
  1. <?php
  2. /*MySQL Dump Split to Tables
  3. * script supplied by Edmonds Commerce
  4. * www.edmondscommerce.co.uk
  5. * if you like it, please link back with a do-follow
  6. */
  7. echo '<h1>MySQL Dump Split to Tables</h1>';
  8. set_time_limit(600);
  9. if(!isset($_GET['dump_file'])){
  10.     echo '<form><b>Dump File Path:</b> <input name="dump_file"> <input type="submit" value="go"></form>';
  11. }else{
  12.     $handle = @fopen($_GET['dump_file'], "r");
  13.     if ($handle) {
  14.         while (!feof($handle)) {
  15.             $line = fgets($handle);
  16.             if(strstr($line, 'CREATE TABLE')){
  17.                 if(isset($out)){
  18.                     fclose($out);
  19.                     unset($out);
  20.                 }
  21.                 preg_match('%CREATE TABLE `(.+?)`%', $line, $matches);
  22.                 $table_name = $matches[1];
  23.                 $out = fopen($table_name . '.sql', 'w');
  24.                 fwrite($out, $line . "\n");
  25.             }else{
  26.                 if(isset($out)){
  27.                     fwrite($out, $line . "\n");
  28.                 }
  29.             }   
  30.         }
  31.         fclose($out);
  32.         fclose($handle);
  33.     }   
  34. }
  35. echo '<h1>Done</h1>'
  36. ?>

Bookmark this Post
Add 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to Del.icio.usAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to diggAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to FURLAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to blinklistAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to redditAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to Feed Me LinksAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to TechnoratiAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to Yahoo My WebAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to NewsvineAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to SocializerAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to Ma.gnoliaAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to Stumble UponAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to Google BookmarksAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to RawSugarAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to SquidooAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to SpurlAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to BlinkBitsAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to NetvouzAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to RojoAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to BlogmarksAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to ShadowsAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to Co.mments
Add 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to ScuttleAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to BloglinesAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to TailrankAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to SegnaloAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to OKnotizieAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to NetscapeAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to Bookmark.itAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to AskAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to SmarkingAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to LinkagogoAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to DeliriousAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to SocialdustAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to Live-MSNAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to SlashDotAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to SphinnAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to DiggitaAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to SeotribuAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to FaceBookAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to UpnewsAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to WikioAdd 'MySQL Dump Partial Restore - Split MySQL Dump into Tables' to Social Bookmarking Reloaded

Feed | Respond | Trackback

3 Responses to “MySQL Dump Partial Restore - Split MySQL Dump into Tables”

  1. marius Says:
    May 10th, 2008 at 8:50 am

    Excellent piece of coding. Had an error in the mysqldump that prevented to whole backup from being restored. With your script it was easy to do a partial restore.

    Thanks, Marius

  2. admin Says:
    May 10th, 2008 at 1:16 pm

    glad you liked it :-)

  3. Max Says:
    June 13th, 2008 at 2:19 pm

    Hey Edmond, thanks for the link. Adds nicely to my blog post on my way of doing partial restore.

Leave a Reply

  • RSS Feed
  • Categories

    • apache
    • barcode
    • creloaded
    • curl
    • customer services
    • debugging
    • ecommerce
    • email
    • excel
    • firefox
    • flash
    • gd
    • graphs
    • hosting
    • icecat
    • internet news
    • javascript
    • link building
    • linux
    • magento
    • management
    • mod_rewrite
    • mysql
    • oscommerce
    • php
    • plesk
    • product catalogue
    • product feed
    • programming
    • regular expressions
    • scraping
    • search engine optimisation
    • spidering
    • ubuntu
    • web design
    • web development
    • Windows
    • xampp
    • zip
  • Archives

    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
  • Tags

    addons advanced adverts blackhat blocking css curl development directories find firefox google hosts file html javascript keywords links msn mysql myths operators oscommerce paid links paid placement performance php ppc reciprocal linking replace screen scraping security seo serp speed spider spidering tuning user friendly vista web web design web developer
  • Random Posts

    • osCommerce Password Reset Using phpMyAdmin
    • MySQL Copy Table from One Database to Another
    • Freelance osCommerce UK
    • Handy Easy Javascript
    • Flash and PHP Charts and Graphs
    • CRELoaded Remove Google Ads -
    • HP Printer on Ubuntu
    • SEO, Links, Pagrank and Anchor Text
    • PHP MySQL Query Function with Easy Error Message
    • Ecommerce Back Office Optimisations

Edmonds Commerce related questions? Send us a message or call us on 0844 357 0201.

Freelance PHP Web Design UK Commercial Web Design