MySQL LOAD DATA infile parsing

Source: Internet
Author: User

LOAD DATA [low_priority] [LOCAL] INFILE ' file_name.txt ' [REPLACE | IGNORE]

Into TABLE tbl_name
[Fields
[TERMINATED by ' \ t ']
[Optionally] Enclosed by "]
[escaped by ' \ \ ']
[LINES TERMINATED by ' \ n ']
[IGNORE number LINES]
[(Col_name,...)]

Custom syntax

The general rules of use for fields and lines are (in the process of importing and exporting, the symbols must be the same)
Load Data InFile ' c:/data.txt ' into Table ' tabletest ' fields Terminated by ', ' enclosed by ' "' escaped by '" ' Lines Termina Ted by ' \ r \ n ';

Fields Terminated by ', ' enclosed by ' "' escaped by '" '
Indicates that each field is separated by commas and the contents are enclosed in double quotation marks

Lines Terminated by ' \ r \ n ';
Indicates that each piece of data is separated by a newline character.

The Replace and Ignore keywords control the repetitive processing of existing unique key records. If you specify replace, the new row replaces the existing rows that have the same unique key value. If you specify ignore, skip the input of the duplicate rows of existing rows that have unique keys. If you do not specify an option, when a duplicate key is found, an error occurs, and the remainder of the text file is ignored

If you do not specify a fields clause, the default value is the same as if you write:

Fields TERMINATED by ' \ t ' enclosed by ' \ escaped by ' \ \ '

If you do not specify a lines clause, the default value is the same as if you write:

LINES TERMINATED by ' \ n '

The general rules of use for fields and lines are (in the process of importing and exporting, the symbols must be the same)
In other words, the default value causes the input to be read, and the LOAD DATA infile behaves as follows:

Look for row boundaries at line breaks
To divide rows into fields at a locator
Do not expect fields to be encapsulated by any quotation mark characters
A locator, line feed, or "\" that begins with "\" is interpreted as part of the literal character of the field value.

MySQL LOAD DATA infile parsing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.