This prevents the value that may contain a comma (,) will be interpreted as the field separator. Each line contains values of each column of the row in the result set.Įach value is enclosed by double quotation marks indicated by FIELDS ENCLOSED BY '”' clause. Each line is terminated by a sequence of carriage return and a line feed character specified by the LINES TERMINATED BY '\r\n' clause. The CSV file contains lines of rows in the result set. The statement created a CSV file named cancelled_orders.csv in the C:\tmp folder that contains the result set. WHERE status = 'Cancelled' INTO OUTFILE 'C:/tmp/cancelled_orders.csv' FIELDS ENCLOSED BY '"' TERMINATED BY ' ' ESCAPED BY '"' LINES TERMINATED BY '\r\n' Code language: SQL (Structured Query Language) ( sql ) To export this result set into a CSV file, you add some clauses to the query above as follows: SELECT WHERE status = 'Cancelled' Code language: SQL (Structured Query Language) ( sql ) OrderNumber, status, orderDate, requiredDate, comments The following query selects cancelled orders from the orders table: SELECT The MySQL server’s process has the write access to the target folder that contains the target CSV file.MySQL provides an easy way to export the query’s result into a CSV file that resides in the database server.īefore exporting data, you must ensure that: It will be useful to have data from MySQL database in CSV file format because you can analyze and format the data in the way you want. The CSV stands for comma separated values. You often use the CSV file format to exchange data between applications such as Microsoft Excel, Open Office, Google Docs, etc. Summary: in this tutorial, you will learn various techniques of how to export a MySQL table to a CSV file.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |