Skip to content

Instantly share code, notes, and snippets.

@PeterJuel
Created May 8, 2012 12:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save PeterJuel/2634518 to your computer and use it in GitHub Desktop.
Save PeterJuel/2634518 to your computer and use it in GitHub Desktop.
PHP: Import huge SQL file to MySQL
$mysqli = new mysqli('localhost', '#username', '#password', '#database');
$handle = fopen('sqldump.sql', 'rb');
if ($handle) {
while (!feof($handle)) {
// This assumes you don't have a row that is > 1MB (1000000)
// which is unlikely given the size of your DB
// Note that it has a DIRECT effect on your scripts memory
// usage.
$buffer = stream_get_line($handle, 1000000, ";\n");
$mysqli->query($buffer);
}
}
echo "Peak MB: ",memory_get_peak_usage(true)/1024/1024;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment