How do you export query results in the MySQL command li…
In the MySQL command line, you can use the following command to export query results:
- Export as a text file:
SELECT * FROM table_name INTO OUTFILE '/path/to/file.txt';
This will export the query result as a text file and save the file to the specified path.
- Export as a CSV file:
SELECT * FROM table_name INTO OUTFILE '/path/to/file.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
This will export the query results to a CSV file and save the file at the specified path. Fields will be separated by commas, field values will be enclosed in double quotation marks, and lines will be separated by line breaks.
Note: The export file path must be a path that the MySQL server can access. If the file path is invalid or does not have write permissions, the export operation will fail.