MySQL SELECT INTO OUTFILE: Export Data to Files
In MySQL, the SELECT INTO OUTFILE statement is used to export query results to a file. The basic syntax for using this statement is as follows:
SELECT column1, column2, ...
INTO OUTFILE 'file_path'
FROM table_name
WHERE condition;
In this case, column1, column2, … are the names of the columns to be selected, ‘file_path’ is the file path to export to, table_name is the name of the table to query, and condition is the optional query condition.
For example, to export all data in the table to a file named output.csv, you can use the following query:
SELECT *
INTO OUTFILE '/path/to/output.csv'
FROM table_name;
Please note that when using the SELECT INTO OUTFILE statement, make sure that the MySQL server has write permissions to the specified file path. Additionally, the exported file will be saved on the MySQL server, not on the client computer.