views:

107

answers:

1

how to store the mysql query result into a local csv file ?

edit 2 :

because i dont have access in the remote machine .

+3  A: 

You can try doing :

SELECT a,b,c
FROM table_name
INTO OUTFILE '/tmp/file.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'

We use the OUTFILE clause here to store the output into a CSV file.
We enclose the fields in double-quotes to handle field values that have the comma in them and we separate the fields by comma and separate individual line using newline.

codaddict
if suppose i dont have access in remote machine to store the generated file
joe
You can use the mysql-client on the local machine, connect to the remote DB server and then issue the above query to store the result on the local machine.
codaddict
ya .. i am facing that issue . How to resolve that ?
joe