When I run query #1:
SELECT * FROM $TABLE INTO OUTFILE $FILE CHARACTER SET utf8 FIELDS ESCAPED BY '\\\\' TERMINATED BY '|';
There is this one field value that is outputted as:
blah\0
I am trying to get identical output without using INTO OUTFILE
.
query #2 with Perl code:
$query = $db->prepare("SELECT * FROM $TABLE");
$query->execute;
open(FILE_OUT, ">$FILE");
However, the same column above is outputted as
blah
So the \0
character (ASCII NUL) is outputted differently. How do I modify query #2 to output blah\0
?
The modification could be in either MySQL query or Perl. The column's Collation is utf8_general_ci. I've tried using CONVERT($column using utf8)
but that still displayed blah
, and I'm not sure how I would apply it to every column of every table when outputting.
Update:
This Perl code worked in escaping the NUL character.
$row =~ s/\0/\\0/g;
But there are many other MySQL special characters, is there a way to escape them all at once instead of handling them one by one?