MySQL的enclosed-by和escaped-by

        In the process of using mysql, I often use the two functions of "load data infile" and "select into outfile" to quickly "move" data. Careful children's shoes will find that these two SQL statements have:

line terminated by 'string'

fields terminated by 'string'

enclosed by 'char'

escaped by 'char'

 

One, in "load data infile":

First look at the role of enclosed-by:

 1. If there is an "enclosed by" character in the field value, and the previous character is an "escaped by" character, after importing into mysql, the "escaped by" character will be removed.

 2. For the field value wrapped by "enclosed by" in the text, if there are two consecutive "enclosed by" characters in the value, it will become one after importing.

 

Take a look at the escaped-by effect:

1. If the "escaped by" character appears in the field value, the character will be removed and the next character will be retained;

2, but the following special two "next to" characters will be "reversed"

"\\0" -- reverse escape to \0 (0x00)

"\\b", "\\n", "\\r", "\\t" -- 反转义成\b, \n, \r, \t

"\\Z" -- reverse to ascii code 26

"\\N" -- reverse escape to NULL

 

Two, in "select into outfile":

Let's take a look at the role of enclosed-by first:

1. Optionally of enclosed-by clause is useful

With optional, only use the enclosed-by character "wrapping" for fields of string type;

Without optional, all fields are "wrapped" with enclosed-by characters.

 

Finally, look at the role of escaped-by:

1. Escape the characters in the following 4 cases

"escaped by" characters in field value

"enclosed by" characters in field value

The first character of the "fields terminated by" and "lines terminated by" strings in the field value

ascii code 0 -> becomes two bytes after escaping

first byte - '\\'

Second byte - '0' (character 0, not ascii 0)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326385188&siteId=291194637