Handling large mysqldump import with PHP

Client’s intranet is on an Apache / Windows box on the other side of the continent and we needed a quick way to synch up our development environment with theirs. Their database has been accumulating production data for over 36 months and the filesize of the export from phpMyAdmin reads 11.7MB. To avoid manual export from phpMyAdmin, we used the PHP system function to automate creation of the dump file as follows:

$cmd     =     “\path\to\mysql\bin\mysqldump.exe ”

.    “–skip-extended-insert ”
.    “–skip-add-locks ”
.    “–skip-add-drop-table ”
.    “–skip-set-charset ”
.    “–skip-comments ”
.    “–result-file=$filepath/$dump_filename -r $filepath/$dump_filename ”
.    “–user dbusername ”
.    “–password=dbpassword ”
.    “dbname”
;

system ( $cmd );

The resulting dump file from mysqldump is 15.4MB. We couldn’t use phpMyAdmin to import w/out suffering through several timeouts before the import was completed. What to do? We found this amazing script by Alexey Ozerov: BigDump

The BigDump script basically times itself out every 2 to 3 seconds (configurable) and restarts the dump where it left off from the previous import. It has a progress bar so you get visual status on the import.

Links

system: PHP function for CLI executable.
phpMyAdmin: PHP based MySQL administrative tools.
mysqldump: MySQL database backup program.
BigDump PHP script: awesome script that assists in huge dump file imports via http.
Notepad++: Windows text editor that preserves carriage return or line feed (CRLF, \r\n) format of the original document. Really helpful when editing a dump file created for use with BigDump.