1

I'm trying to figure out the syntax to export the results of a MySQL query to the desktop as a CSV file via SSH. Here's what I'm trying:

 SELECT * INTO OUTFILE 'C:\Users\Jim Smith\Desktop\zyzyz.csv'
 FIELDS TERMINATED BY ',' 
 OPTIONALLY ENCLOSED BY '\"'  
 LINES TERMINATED BY '\r\n' 
 from <table> limit 5;

The query itself works fine, but the file doesn't appear on the desktop. What should I change to get it to show up?

0

In windows use \\ or / while using in path of file. your command should be as follow

SELECT * INTO OUTFILE 'C:\\Users\\Jim Smith\\Desktop\\zyzyz.csv' FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\r\n'
from limit 5;

or

SELECT * INTO OUTFILE 'C:/Users/Jim Smith/Desktop/zyzyz.csv' FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\r\n'
from limit 5;

Hope it helps

1
  • Yes, and also under Windows - security rules make hard to write into user folders (even when application run by LoalSystem). Better to create folder on disk c:\ in root, c;\uptput and redirect query for this folder
    – a_vlad
    Nov 13 '16 at 2:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.