Making BigDump like mysqldump

Update: See Alexey’s comment at the bottom, it seems like I missed reading some important info at the top of the bigdump file.

I just had to import a dump made with mysqldump using BigDump. The reason being that the dump file in question was over 1GB in size. For files this big BigDump is perfect. As it turns out BigDump does not like dumps made with mysqldump at all, not if you are unlucky anyway, which of course is just what I was.

Apparently mysqldump can insert statements like this into the SQL file:

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;

I am no SQL expert, but in 2 years of developing with MySQL almost exclusively I’ve never seen anything like it and I don’t understand what statements like this are good for. Please enlighten me by commenting if you do.

Anyway, it turns our that BigDump, or the mechanism of importing that BigDump is using – does not like lines like this at all, at least not sometimes. It prefers backups made with phpMyAdmin.

So I modified BigDump, my version looks something like this somewhere between lines 500 and 600:

// Skip comments and blank lines only if NOT in parents

      if (!$inparents)
      { $skipline=false;
        reset($comment);
        foreach ($comment as $comment_value){ 
	  if (!$inparents && (trim($dumpline)=="" || strpos($dumpline, $comment_value) === 0 || strpos ($dumpline, "/*!") !== false))
          { $skipline=true;
            break;
          }
        }
        if ($skipline)
        { $linenumber++;
          continue;
        }
      }

// Remove double back-slashes from the dumpline prior to count the quotes ('\\' can only be within strings)
      
      $dumpline_deslashed = str_replace ("\\\\","",$dumpline);

// Count ' and \' in the dumpline to avoid query break within a text field ending by ;
// Please don't use double quotes ('"')to surround strings, it wont work

      $parents=substr_count ($dumpline_deslashed, "'")-substr_count ($dumpline_deslashed, "\\'");
      if ($parents % 2 != 0)
        $inparents=!$inparents;

// Add the line to query

      if(strpos ($dumpline, "/*!") !== false)
        $dumpline = "";
	
      $query .= $dumpline;

Notice how I’ve added strpos ($dumpline, “/*!”) !== false in two strategic places. After these changes everything went smoothly and when I checked the data in phpMyAdmin everything looked OK.

Related Posts

Tags: , ,