Use load data to import formatted files to MySQL tables

Source: Internet
Author: User

Load dataThe usage is as follows:

Load data [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name.txt'

[REPLACE | IGNORE]

INTO TABLE Tbl_name

[FIELDS//Field

[Terminated by 'string']//FieldRoomDelimiter

[[OPTIONALLY] enclosed by 'Char ']//Including the field symbol

[Escaped by 'Char ']//FieldEscape Character

]

[LINES

[Starting by 'string']//Start string of the row

[Terminated by 'string']//LineEnd splitCharacterNo.

]

[IGNORE Number LINES]//Skip the previous stepNumberLine

[(Col_name_or_user_var,...)] //Field name

[SET Col_name = Expr,...)]

 

For example, a data text is as follows:

Stock CodeStock nameKickoffClosing Price

Def: "000001 ","Deep DevelopmentA "," 13.24 "," 13.56"

Def: "000002 ","VankeA "," 24.43 "," 24.77"


Load data local infile 'table_name.txt'

Into table database_name

Fields terminated by ', 'enabledby' "'escaped '\'

Lines starting by 'def'

IGNORE 1 LINES

(Stock_code, stock_name, opening, settlement );


Let's take a look at my actual operations:


If you log on to the remote mysql server and want to import your local text to the database, local is required. The commands are different.

Load data local infile '/usr/local/mysql/var/Statistic/Spam.txt' into table Spam;

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.