Can I output results of a MySQL query to a csv file via Putty?

Posted on

QUESTION :

I’ve typed the following code to output the csv file , but it shows an error

mysql> SELECT *INFO OUTFILE ‘d:/student.csv’ FIELDS TERMINATED BY ‘,’
OPTIONALLY ENCLOSED BY ‘”‘ LINES TERMINATED BY ‘rn’ FROM
tbl_student;

does anybody know what’s wrong here?

ANSWER :

SELECT *INFO
FROM tbl_student
INTO OUTFILE 'd:/student.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY 'n'

Keep in mind that the output file must not already exist and that the user MySQL is running as has write permissions to the directory MySQL is attempting to write the file to.

Leave a Reply

Your email address will not be published. Required fields are marked *