Mysql implementation Query Results export CSV file and import CSV file to database operation _mysql

Source: Internet
Author: User
Tags mysql query mysql command line
This article mainly introduces the MySQL implementation query results export CSV file and import CSV file to the database operation, combined with instance form analysis of MySQL related database export, import statements using methods and operational considerations, the need for friends can refer to the next

This article describes the MySQL implementation query results export CSV file and import CSV file to the database operation. Share to everyone for your reference, as follows:

MySQL Query results export CSV file:

Select LogTime, OperatingSystem, Imeifrom gamecenterlogswhere  operatingsystem >= 1 and OperatingSystem <= 3group by Operatingsystem,imeiinto outfile '/tmp_logs/tmp.csv ' fields TERMINATED by ', ' optionally enclosed by ' # ' LINES TE rminated by ' \ r \ n '

fields TERMINATED BY ',' Set the separator for a field

OPTIONALLY ENCLOSED BY '#' Set the field contents to be a string, use ' # ' contains

LINES TERMINATED BY '\r\n' Data row Separator

Export File Contents:

1453513680,3, #hello word#\r\n
1453515470,2, #title content#\r\n

MySQL command line import CSV file to database:

Load data infile '/tmp_logs/tmp.csv ' into table gamecenterdaulogs fields terminated by ', ' optionally enclosed by ' # ' lines Terminated by ' \ r \ n '


There may be different operating systems, the data row delimiter for the exported CSV file is not necessarily \ r \ n, you can use the cat -A /tmp_logs/tmp.csv view end character


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.