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.