Search This Blog

Friday, 6 May 2011

output CSV from mysql

1. Make sure you've got FILE permission

mysql> grant FILE on *.* to matt;

2. make sure mysql can write to the destination directory - I used /tmp

mysql> select 'hello world' into outfile '/tmp/destination.txt';

3. select your csv output
SELECT order_id,product_name,qty
FROM orders
INTO OUTFILE
'/tmp/destination.csv'
FIELDS TERMINATED BY
','
ENCLOSED BY
'"'
LINES TERMINATED BY
'\n';

1 comment:

  1. You need an output directory where owner is root:root and sticky bit is set with chmod 1777

    ReplyDelete