Import a CSV file into the MySQL database

Source: Internet
Author: User
Tags character set relative

The unified encoding method is Utf-8, and the CSV file encoding is set to Utf-8.

Create a new table in the database, column properties and CSV file to match, note the * * Month * * day, etc. in CSV set to date format, rather than strings, and so on, so you can import time.

Set to the selected time column, right-click the table property, and set it to a date.

?

1 2 3 4 The LOAD DATA INFILE "**.csv" into the TABLE XX CHARACTER SET UTF8 FIELDS terminated by ",";

The load data uses the following format:

LOAD DATA [low_priority] [local] INFILE ' file_name.txt ' [REPLACE | IGNORE]

Into TABLE tbl_name

[FIELDS

[Terminated by ' t ']

[Optionally] Enclosed by ']

[escaped by ']]

[LINES terminated by ' n ']

[IGNORE number LINES]

[(Col_name,...)]

which

Low_priority

If the user specifies this keyword, execution of the LOAD DATA statement is deferred until no other client is reading the table.

Local

If the local keyword is specified, it interprets the connected client:

? If local is specified, the client component on the client host reads the file and sends it to the server. You can give the full path of the file to determine its exact location. If a relative path is given, the file name is relative to the directory where the client component started.

? If no local is specified, the file is located on the server's host and is read directly by the server.

When you locate a file from a server host, the server uses the following rules:

? If the full path is given, the server uses the path name.

? If a relative path is given to one or more predecessor artifacts, the server searches for files relative to the server's data directory.

? If given a filename without a predecessor, the server searches for files from the database directory of the current database.

--character Set:mysql Character set, indicated to be used to interpret information in a file

--into table: Which tables are imported into

--fields terminated by: what as a separator

--enclosed by: What is surrounded by (required for output)

CSV, the abbreviation for comma separated value (comma-separated values), is usually a plain text file. Inside the data to, split, so FIELDS terminated by ","

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.