Mysql – Exported CSV from MySQL doesn’t appear in specified directory

csvexportMySQL

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?

Best Answer

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