MySQL load data infile parsing, mysqlinfile

Source: Internet
Author: User

MySQL load data infile parsing, mysqlinfile

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 use rules of FIELDS and LINES are (the symbols after by must be consistent during the import and export processes)
Load Data InFile 'C:/Data.txt 'into table' tabletest' Fields Terminated By ', 'enabled' "'elasticed' By'" 'Lines Terminated By '\ r \ n ';

Fields Terminated By ', 'enabledby' "'escaped '"'
Each field is separated by a comma. The content is included in double quotation marks.

Lines Terminated By '\ r \ n ';
Indicates that each piece of data is separated by a line break.

 

The REPLACE and IGNORE keywords control repeated processing of existing unique key records. If you specify REPLACE, the new row replaces the existing row with the same unique key value. If you specify IGNORE, skip the input of duplicate rows of existing rows with a unique key. If you do not specify any option, an error occurs when the duplicate key is found and the remaining part of the text file is ignored.

 

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

Fields terminated by '\ t' enclosed by ''escaped '\\'

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

Lines terminated by '\ N'

The general use rules of FIELDS and LINES are (the symbols after by must be consistent during the import and export processes)
In other words, when the default value causes reading input, load data infile performs as follows:

Search for line boundary at line breaks
Split the row into fields at the location Operator
Do not expect fields to be enclosed by any quotation marks
The delimiters, linefeeds, or "\" starting with "\" are part of the literal characters of the field value.

 

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.