Use scripts to import csv files to mysql_MySQL

Source: Internet
Author: User
1. by default, csv files made in windows are in the gbk character set, while mysql sets the default utf8 character set. Therefore, convert the files to the utf8 format. Iconv-fgbk-tutf8tmpfile name .csv-otmpfile name 2.csv 2. use the SQL command to import loaddatainfile #... 1. by default, csv files made in windows are in the gbk character set, while mysql sets the default utf8 character set. Therefore, convert the files to the utf8 format.

Iconv-f GBK-t UTF8/tmp/file name .csv-o/tmp/file name 2.csv

2. use SQL commands to import data

Load data infile '/tmp/mailut2.csv' into table db1.d fields terminated by ', 'lines terminated by' \ n' ignore 1 lines (id, email, passwords, name, address, dept, mobile );

Ignore 1 lines ignores 1st rows, and 1st rows are header rows.

(Id, email, passwords, name, address, dept, mobile) this refers to the import in the order of this field, that is, the first column of the csv file into the id field of the table, the second column imports the email field ......

If the csv file is followed by a column, ignore it.

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.