List:General Discussion« Previous MessageNext Message »
From:Dan Nelson Date:February 7 2003 4:29pm
Subject:Re: backslash before newline
View as plain text  
In the last episode (Feb 06), Michael Boudreau said:
> Here's something weird: text strings containing newlines seem to have a 
> backslash character added when the data is exported from the database. 
> (MySQL 3.23.37 on Solaris--yes we're upgrading to .54)
> 
> However, when I read the data out to a file...
> 
>    mysql> select review into outfile '/tmp/MS55038rev1.txt' from MsReviews where
> msid=55038 and msreviewid=1;
>    Query OK, 1 row affected (0.00 sec)
>    mysql> quit
>    Bye
> 
> The newline seems to have had a "\" (backslash, octal 134) inserted 
> before it:
> 
>    mss (mrb)% more /tmp/MS55038rev1.txt
>    123\
>    456

This is documented behaviour.  INTO OUTFILE is the inverse of LOAD DATA
INFILE, and escapes fields in exactly the same way.  From the docs:

     `SELECT ...  INTO OUTFILE' is the complement of `LOAD DATA
     INFILE'; the syntax for the `export_options' part of the statement
     consists of the same `FIELDS' and `LINES' clauses that are used
     with the `LOAD DATA INFILE' statement.  *Note `LOAD DATA': LOAD
     DATA.

   * If you use `INTO DUMPFILE' instead of `INTO OUTFILE', MySQL will
     only write one row into the file, without any column or line
     terminations and without any escaping.  This is useful if you want
     to store a blob in a file.

-- 
	Dan Nelson
	dnelson@stripped
Thread
backslash before newlineUnknown Sender6 Feb
  • Re: backslash before newlineKeith C. Ivey7 Feb
  • Re: backslash before newlineDan Nelson7 Feb