1

I'm trying to export a table in MySQL as a CSV, but I'm having trouble. I've tried two approaches, neither of which have worked.

First:

SELECT * 
INTO OUTFILE '/path/to/filename.csv' 
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"' 
ESCAPED BY '\\' 
LINES TERMINATED BY '\n' 
FROM table;

Second:

mysqldump -u [username] -p -t -T/path/to/directory [database] [table] --fields-enclosed-by=\" --fields-terminated-by=,
1
  • What is wrong with the first one? Commented Aug 27, 2012 at 7:17

2 Answers 2

1

try this example,

SELECT order_id,product_name,qty FROM orders
INTO OUTFILE '/tmp/orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'

SOURCE

Sign up to request clarification or add additional context in comments.

Comments

0

SELECT order_id,product_name,qty FROM orders INTO OUTFILE '/tmp/orders.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'

is correct if it is not worked then try to avoid path of the file....just give file name and after execution look resulted file in '/var/lib/mysql/dbname'.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.