-- If you are using linux, SELECT id, filename FROM attachments INTO OUTFILE '/tmp/results.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY ' '; -- and find the csv file /tmp