Instructions for importing txt file data in mysql: bitsCN.com
Basic MySQL database import and export operations
1 Table tt format:
Create table 'TT '(
'IND 'Int not null auto_increment,
'Name' char (100) default NULL,
Primary key ('IND ')
)
2. example of d.txt:
1,
2, B
3, c
3. import command:
Mysql> load data infile 'd.txt 'into table tt
-> Fields terminated ','
-> Lines terminated by '/r/N'
Note:
1) you can use absolute paths for files, such as 'C:/d.txt '. Otherwise, put the files in the root directory of the database.
2) fields are separated by commas, so fields terminated by ',' is required; otherwise, the import fails.
3) because the rows in Winsows are separated by "/r/n", lines must be terminated by '/r/N ',
If this parameter is not set, the import can be successful, but an "/r" control character will be imported, which may be visualized
MySQL tool does not see the same field, but the MySQL command line shows obvious confusion.
4) If the tt table is not empty and the ind value in the file already exists in the table, an error is prompted and the import fails.
Import only namefield, and the content of file d.txt:
A
B
C
Mysql> load data infile 'd.txt 'into table tt
-> Lines terminated by '/r/N'
-> (Name );
The load data command also supports more complex text formats and file encoding. For more information, see the official documentation.
5. when exporting data to a windows text file, the same settings are also required for ease of viewing.
Mysql> select * from tt into outfile 'd.txt'
-> Fields terminated ','
-> Lines terminated by '/r/N'
BitsCN.com