OUTFILE
Example
Section titled “Example”SELECT column1, column2FROM table_nameINTO OUTFILE '/tmp/outfile.csv'FIELDS TERMINATED BY ','ENCLOSED BY '"'LINES TERMINATED BY '\n';Output
Section titled “Output”/path/to/yourfile.csvExplanation
Section titled “Explanation”The code excerpt above shows how to output the result of a SQL query to a CSV file using MySQL’s OUTFILE function. The INTO OUTFILE clause specifies the destination of the exported CSV file, while FIELDS TERMINATED BY,ENCLOSED BY, and LINES TERMINATED BY define the CSV’s formatting. This snippet exports column1 and column2 from table_name into a CSV file named outfile.csv, located in the /tmp directory.