Instructions for importing txt file data in mysql _ MySQL

Source: Internet
Author: User
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

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.