Example query for direct csv saving from mysql. Using query to import or export data is the fastest method. You can export your query results as csv with custom syntax. You have to use union to join headers if you need headers. Also you need write permissions for mysql to write the csv into the directory. Usually web directory has access for mysql out of the box.
Source code viewer
/* Add column headers. */ /* Union for adding column headers with data. */ /* Your query for the results. */ /* Data for the exported csv file, use directory that has write permissions for mysqlserver. */ INTO OUTFILE '/var/www/my_file.csv' FIELDS TERMINATED BY ';' ENCLOSED BY '"' LINES TERMINATED BY '\n';Programming Language: MySQL