SELECT tableColumnName1, tableColumnName2
INTO OUTFILE '/path/to/file/data.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM tableName;
Access Denied
Even if you have been granted the SELECT privilege, you will still need to be granted the FILE privilege, or else access will be denied. Some architects will only grant this privilege to the root user. Another reason that you might receive an access denied message, is because the directory where you are trying to save the CSV file is not writable.
In order to prevent a user from accidentally overwriting an important system file (like etc/passwd), you will be unable to save over a file that already exists on the server.