MySQL - export query results to file
SELECT
p.first_name as "Name", p.last_name as "Surname"
FROM persons p
WHERE p.person_type_id= 2
ORDER BY p.created_at DESC
INTO OUTFILE '/tmp/persons.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
Results of this query will be saved to file /tmp/persons.csv