[MySQL] use the load data local infile statement to quickly import files

Source: Internet
Author: User

To import data from a file to a database, use the load data local infile statement.

 

The default situation is as follows:

Tab is the field separator, and line feed is the record separator.

In this case, no additional conditions are required. simply use the most concise statement:

Load data local infile 'f:/pet.txt 'into Table PET;

 

Some situations are as follows:


Comma ',' is the field separator, and the line break is the record separator.

In this case, only the default delimiter of the record is used, and the field separation conditions must be added:

Load data local infile 'f:/pet1.txt 'into Table pet fields terminated ',';

 

There is also a situation like this:


Comma ',' is the field separator, '*,' is the record separator.

In this case, whether the field or record separator is not the default one, it should be described separately:

Load data local infile 'f:/pet2.txt 'into Table pet fields terminated by', 'Lines terminated '*,';

 

 

Query, use select * from PET; to test the data import result:

In each case:

OK. Import successful!

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.