MySQL Dump Partial Restore - Split MySQL Dump into Tables
April 9th, 2008Read 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.
-
<?php
-
/*MySQL Dump Split to Tables
-
* script supplied by Edmonds Commerce
-
* www.edmondscommerce.co.uk
-
* if you like it, please link back with a do-follow
-
*/
-
echo '<h1>MySQL Dump Split to Tables</h1>';
-
echo '<form><b>Dump File Path:</b> <input name="dump_file"> <input type="submit" value="go"></form>';
-
}else{
-
if ($handle) {
-
}
-
$table_name = $matches[1];
-
}else{
-
}
-
}
-
}
-
}
-
}
-
echo '<h1>Done</h1>'
-
?>












































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
May 10th, 2008 at 1:16 pm
glad you liked it
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.