How to import data into MySQL in a prescribed format

Source: Internet
Author: User

1, first we get the data, the data must be written in a certain format. If you use | To differentiate between fields, line breaks differentiate row

12107    |    Mood 1    |     Today's mood is very bad ah.  12108    |    Weather     |     The weather is fine today.  12109    |    Smug     |     He likes to be smug.  12707    |    Mood 2    |     Yesterday was not happy, today is good.  12107    |    Mood 3    |    Very happy today.

We store the above text as Data.txt, and the text format is UTF8.

2. Create a table

CREATE TABLE IF  not EXISTS' post ' (' ID ' )int(Ten) not NULLauto_increment, ' uid 'int(Ten) not NULL, ' title 'varchar( -) not NULL default 'not named', ' content ' Longtext not NULL,  PRIMARY KEY(' id '),KEY' uid ' (' uid ')) ENGINE=MyISAMDEFAULTCHARSET=UTF8 COMMENT='Post Table'Auto_increment= -;

3. Then we'll write a SQL script that imports data.txt, or write it in a script with the CREATE table.

LOADDATA LOCAL INFILE'C:/users/arvin tang/desktop/data.txt'    --the data to import      into TABLEPostcharacter SetUtf8--Note: Set character setsFields TERMINATED by '|'#注释: Between fields by|to differentiate LINES TERMINATED by '\ n'#注释: The newline (UID, title, content) is differentiated by \ n;

4, good data import completed, we can now look at the data in the post table.

How to import data into MySQL in a prescribed format

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.