Import a csv file to mysql database _ MySQL

Source: Internet
Author: User
Import the csv file to the mysql database bitsCN.com.

The unified encoding method is UTF-8, and the csv file encoding method is set to UTF-8.

Create a new table in the database. the column attributes must be consistent with the csv file. set ** month ** to date format in csv, instead of string, in this way, you can import time and so on.

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

  LOAD DATA INFILE "**.csv"  INTO TABLE XX  CHARACTER SET utf8  FIELDS TERMINATED BY "," ;

The load data format is as follows:

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,...)]

Where,

LOW_PRIORITY

If you specify this keyword, the execution of the load data statement will be delayed until no other client is reading the table.

LOCAL

If the LOCAL keyword is specified, it will explain 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 provide the complete path of the file to determine its exact location. If the relative path is given, the file name is relative to the directory where the client component was started.
? If LOCAL is not specified, the file is located on the server host and is directly read by the server.
When files are located from the server host, the server uses the following rules:
? If a complete path is specified, the server uses this path name.
? If the relative path of one or more front components is specified, the server searches for files in a directory relative to the server.
? If a file name without a front component is specified, the server searches for files from the Database Directory of the current database.

-- Character set: mysql character set, which is used to explain the information in the file

-- Into table: TABLE to which the data is imported

-- Fields terminated by: used as a delimiter

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

Csv, short for Comma Separated Value (Comma-Separated values), is usually a plain text file. The data in it is separated BY, so fields terminated ","

 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.