MySQL Import example of exporting CSV data

Source: Internet
Author: User

CVS file import mysql database command:

The code is as follows Copy Code
Set names UTF8;
LOAD DATA local INFILE ' c:\\resource.csv '
into TABLE Resource
FIELDS terminated by ""
LINES terminated by ' \ r \ n '
(Title,singer);


FIELDS terminated by----field terminating character
Optionally enclosed by----envelope character
LINES terminated by----line terminator


Export data for a period of time to CVS:

  code is as follows copy code

filename= "Data" ' Date--date= $date ' +%y%m%d ' ' ". csv ';
#mysql里先导出数据到 XML, with Select INTO OutFile export, set field separator and record delimiter
/usr/local/webserver/mysql/bin/mysql-h "$mysql _host"-u "$mysql _username"-- password= "$mysql _password"  -E "select *  into outfile ' $data _dir$filename ' FIELDS terminated by ', ' optionally Enclosed by '   LINES terminated by ' \\n '   from $table where intime>= $minTime && intime< $maxTim e; "
#这一步也很重要, you need to convert the encoding to GBK
RM-RF $final _dir$filename && touch $final _dir$filename
iconv-c -F UTF-8 -T gbk  $data _dir$filename >  $final _dir$filename

Use the SELECT into outfile to pour the data out of MySQL, where the field delimiter is \ t, the record delimiter is \ n, and then the encoding of the character is turned on OK!

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.