Mysql exports the query result to the csv method, mysqlcsv

Source: Internet
Author: User

Mysql exports the query result to the csv method, mysqlcsv

To export the mysql query result as csv, you can connect to mysql using php to execute the query, and then use php to generate the csv format of the returned query result for export.

However, this is troublesome and requires php installation on the server.

Export csv data directly using mysql

You can use the into outfile, fields terminated by, optionally enclosed by, and line terminated by statements to export csv files.

Statement format and Function

Into outfile 'exported directory and file name'
Specify the exported directory and file name

Fields terminated by 'delimiter between fields'
Define separators between fields

Optionally enclosed by 'field Terminator'
Characters defining the surrounded field (invalid numeric field)

Lines terminated by 'line delimiters'
Define the delimiter of each line

Example:
Mysql-u rootuse test; select * from table into outfile '/tmp/table.csv 'fields terminated by', 'optionally enclosed by' "'Lines terminated by '\ r \ n ';

After execution, the recorded data in talbe is exported to the/tmp/table.csv file. Each field is separated by commas (,), and the content of the field is enclosed by ". \ r \ n is used to wrap each record.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.