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